@@ -23,7 +23,6 @@ import (
23
23
"fmt"
24
24
"os"
25
25
"strconv"
26
- "sync"
27
26
"testing"
28
27
"time"
29
28
@@ -306,57 +305,3 @@ func TestEmptyDatabaseConfig(t *testing.T) {
306
305
err = anotherConn .Ping (context .Background ())
307
306
require .NoError (t , err )
308
307
}
309
-
310
- func TestConnectionExpiresIdleConnection (t * testing.T ) {
311
- runInDocker , _ := strconv .ParseBool (GetEnv ("CLICKHOUSE_USE_DOCKER" , "true" ))
312
- if ! runInDocker {
313
- t .Skip ("Skip test in cloud environment. This test is not stable in cloud environment, due to race conditions." )
314
- }
315
-
316
- // given
317
- ctx := context .Background ()
318
- testEnv , err := GetTestEnvironment (testSet )
319
- require .NoError (t , err )
320
-
321
- baseConn , err := testClientWithDefaultSettings (testEnv )
322
- require .NoError (t , err )
323
-
324
- expectedConnections := getActiveConnections (t , baseConn )
325
-
326
- // when the client is configured to expire idle connections after 1/10 of a second
327
- opts := clientOptionsFromEnv (testEnv , clickhouse.Settings {})
328
- opts .MaxIdleConns = 20
329
- opts .MaxOpenConns = 20
330
- opts .ConnMaxLifetime = time .Second / 10
331
- conn , err := clickhouse .Open (& opts )
332
- require .NoError (t , err )
333
-
334
- // run 1000 queries in parallel
335
- var wg sync.WaitGroup
336
- const selectToRunAtOnce = 1000
337
- for i := 0 ; i < selectToRunAtOnce ; i ++ {
338
- wg .Add (1 )
339
- go func () {
340
- defer wg .Done ()
341
- r , err := conn .Query (ctx , "SELECT 1" )
342
- require .NoError (t , err )
343
-
344
- r .Close ()
345
- }()
346
- }
347
- wg .Wait ()
348
-
349
- // then we expect that all connections will be closed when they are idle
350
- // retrying for 10 seconds to make sure that the connections are closed
351
- assert .Eventuallyf (t , func () bool {
352
- return getActiveConnections (t , baseConn ) == expectedConnections
353
- }, time .Second * 10 , opts .ConnMaxLifetime , "expected connections to be reset back to %d" , expectedConnections )
354
- }
355
-
356
- func getActiveConnections (t * testing.T , client clickhouse.Conn ) (conns int64 ) {
357
- ctx := context .Background ()
358
- r := client .QueryRow (ctx , "SELECT sum(value) as conns FROM system.metrics WHERE metric LIKE '%Connection'" )
359
- require .NoError (t , r .Err ())
360
- require .NoError (t , r .Scan (& conns ))
361
- return conns
362
- }
0 commit comments