Skip to content

Commit

Permalink
1229 test case more resilient
Browse files Browse the repository at this point in the history
  • Loading branch information
jkaflik committed Apr 15, 2024
1 parent 06a4c43 commit 4d214bb
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tests/issues/1229_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import (

"github.com/ClickHouse/clickhouse-go/v2"
clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func Test1229(t *testing.T) {
const queryTimeout = 2 * time.Second

var (
conn, err = clickhouse_tests.GetConnection("issues", clickhouse.Settings{
"max_execution_time": 60,
Expand All @@ -32,7 +35,7 @@ func Test1229(t *testing.T) {

const insertQuery = "INSERT INTO test_1229 VALUES ('test1value%d', 'test2value%d')"
for i := 0; i < 100; i++ {
withTimeoutCtx, cancel := context.WithTimeout(ctx, time.Millisecond*100)
withTimeoutCtx, cancel := context.WithTimeout(ctx, queryTimeout)
require.NoError(t, conn.Exec(withTimeoutCtx, fmt.Sprintf(insertQuery, i, i)))
cancel()
}
Expand All @@ -43,14 +46,16 @@ func Test1229(t *testing.T) {
wg.Add(1)
go func() {
defer wg.Done()
withTimeoutCtx, cancel := context.WithTimeout(ctx, time.Millisecond*10)
withTimeoutCtx, cancel := context.WithTimeout(ctx, queryTimeout)
defer cancel()
_, _ = conn.Query(withTimeoutCtx, selectQuery)
}()
}

wg.Wait()

openConnections := conn.Stats().Open
require.Equal(t, 0, openConnections)
assert.EventuallyWithT(t, func(ct *assert.CollectT) {
openConnections := conn.Stats().Open
assert.Zerof(ct, openConnections, "open connections: %d", openConnections)
}, time.Second*5, time.Millisecond*10)
}

0 comments on commit 4d214bb

Please sign in to comment.