Skip to content

Commit 4d214bb

Browse files
committed
1229 test case more resilient
1 parent 06a4c43 commit 4d214bb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

tests/issues/1229_test.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ import (
99

1010
"github.com/ClickHouse/clickhouse-go/v2"
1111
clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests"
12+
"github.com/stretchr/testify/assert"
1213
"github.com/stretchr/testify/require"
1314
)
1415

1516
func Test1229(t *testing.T) {
17+
const queryTimeout = 2 * time.Second
18+
1619
var (
1720
conn, err = clickhouse_tests.GetConnection("issues", clickhouse.Settings{
1821
"max_execution_time": 60,
@@ -32,7 +35,7 @@ func Test1229(t *testing.T) {
3235

3336
const insertQuery = "INSERT INTO test_1229 VALUES ('test1value%d', 'test2value%d')"
3437
for i := 0; i < 100; i++ {
35-
withTimeoutCtx, cancel := context.WithTimeout(ctx, time.Millisecond*100)
38+
withTimeoutCtx, cancel := context.WithTimeout(ctx, queryTimeout)
3639
require.NoError(t, conn.Exec(withTimeoutCtx, fmt.Sprintf(insertQuery, i, i)))
3740
cancel()
3841
}
@@ -43,14 +46,16 @@ func Test1229(t *testing.T) {
4346
wg.Add(1)
4447
go func() {
4548
defer wg.Done()
46-
withTimeoutCtx, cancel := context.WithTimeout(ctx, time.Millisecond*10)
49+
withTimeoutCtx, cancel := context.WithTimeout(ctx, queryTimeout)
4750
defer cancel()
4851
_, _ = conn.Query(withTimeoutCtx, selectQuery)
4952
}()
5053
}
5154

5255
wg.Wait()
5356

54-
openConnections := conn.Stats().Open
55-
require.Equal(t, 0, openConnections)
57+
assert.EventuallyWithT(t, func(ct *assert.CollectT) {
58+
openConnections := conn.Stats().Open
59+
assert.Zerof(ct, openConnections, "open connections: %d", openConnections)
60+
}, time.Second*5, time.Millisecond*10)
5661
}

0 commit comments

Comments
 (0)