@@ -9,10 +9,13 @@ import (
9
9
10
10
"github.com/ClickHouse/clickhouse-go/v2"
11
11
clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests"
12
+ "github.com/stretchr/testify/assert"
12
13
"github.com/stretchr/testify/require"
13
14
)
14
15
15
16
func Test1229 (t * testing.T ) {
17
+ const queryTimeout = 2 * time .Second
18
+
16
19
var (
17
20
conn , err = clickhouse_tests .GetConnection ("issues" , clickhouse.Settings {
18
21
"max_execution_time" : 60 ,
@@ -32,7 +35,7 @@ func Test1229(t *testing.T) {
32
35
33
36
const insertQuery = "INSERT INTO test_1229 VALUES ('test1value%d', 'test2value%d')"
34
37
for i := 0 ; i < 100 ; i ++ {
35
- withTimeoutCtx , cancel := context .WithTimeout (ctx , time . Millisecond * 100 )
38
+ withTimeoutCtx , cancel := context .WithTimeout (ctx , queryTimeout )
36
39
require .NoError (t , conn .Exec (withTimeoutCtx , fmt .Sprintf (insertQuery , i , i )))
37
40
cancel ()
38
41
}
@@ -43,14 +46,16 @@ func Test1229(t *testing.T) {
43
46
wg .Add (1 )
44
47
go func () {
45
48
defer wg .Done ()
46
- withTimeoutCtx , cancel := context .WithTimeout (ctx , time . Millisecond * 10 )
49
+ withTimeoutCtx , cancel := context .WithTimeout (ctx , queryTimeout )
47
50
defer cancel ()
48
51
_ , _ = conn .Query (withTimeoutCtx , selectQuery )
49
52
}()
50
53
}
51
54
52
55
wg .Wait ()
53
56
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 )
56
61
}
0 commit comments