|
| 1 | +package issues |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "sync" |
| 7 | + "testing" |
| 8 | + "time" |
| 9 | + |
| 10 | + "github.com/ClickHouse/clickhouse-go/v2" |
| 11 | + clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests" |
| 12 | + "github.com/stretchr/testify/require" |
| 13 | +) |
| 14 | + |
| 15 | +func Test1229(t *testing.T) { |
| 16 | + var ( |
| 17 | + conn, err = clickhouse_tests.GetConnection("issues", clickhouse.Settings{ |
| 18 | + "max_execution_time": 60, |
| 19 | + "allow_experimental_object_type": true, |
| 20 | + }, nil, &clickhouse.Compression{ |
| 21 | + Method: clickhouse.CompressionLZ4, |
| 22 | + }) |
| 23 | + ) |
| 24 | + require.NoError(t, err) |
| 25 | + ctx := context.Background() |
| 26 | + const ddl = "CREATE TABLE IF NOT EXISTS test_1229 (`test1` String, `test2` String) Engine = Memory" |
| 27 | + require.NoError(t, conn.Exec(ctx, ddl)) |
| 28 | + |
| 29 | + defer func() { |
| 30 | + require.NoError(t, conn.Exec(ctx, "DROP TABLE IF EXISTS test_1229")) |
| 31 | + }() |
| 32 | + |
| 33 | + const insertQuery = "INSERT INTO test_1229 VALUES ('test1value%d', 'test2value%d')" |
| 34 | + for i := 0; i < 100; i++ { |
| 35 | + withTimeoutCtx, cancel := context.WithTimeout(ctx, time.Millisecond*100) |
| 36 | + require.NoError(t, conn.Exec(withTimeoutCtx, fmt.Sprintf(insertQuery, i, i))) |
| 37 | + cancel() |
| 38 | + } |
| 39 | + |
| 40 | + wg := new(sync.WaitGroup) |
| 41 | + const selectQuery = "SELECT test1, test2 FROM test_1229" |
| 42 | + for i := 0; i < 100; i++ { |
| 43 | + wg.Add(1) |
| 44 | + go func() { |
| 45 | + defer wg.Done() |
| 46 | + withTimeoutCtx, cancel := context.WithTimeout(ctx, time.Millisecond*10) |
| 47 | + defer cancel() |
| 48 | + _, _ = conn.Query(withTimeoutCtx, selectQuery) |
| 49 | + }() |
| 50 | + } |
| 51 | + |
| 52 | + wg.Wait() |
| 53 | + |
| 54 | + openConnections := conn.Stats().Open |
| 55 | + require.Equal(t, 0, openConnections) |
| 56 | +} |
0 commit comments