From b19a1f4464fbae68c6793e5d056efefac948936b Mon Sep 17 00:00:00 2001 From: Dale McDiarmid Date: Tue, 3 May 2022 12:49:09 +0100 Subject: [PATCH] =?UTF-8?q?Deadlock=20test=20for=20548=C2=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/issues/548_test.go | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/issues/548_test.go diff --git a/tests/issues/548_test.go b/tests/issues/548_test.go new file mode 100644 index 0000000000..d9954fc2ab --- /dev/null +++ b/tests/issues/548_test.go @@ -0,0 +1,46 @@ +package issues + +import ( + "context" + "testing" + "time" + + "github.com/ClickHouse/clickhouse-go/v2" + "github.com/stretchr/testify/assert" +) + +func Test548(t *testing.T) { + var ( + ctx, cancel = context.WithTimeout(context.Background(), time.Second) + conn, err = clickhouse.Open(&clickhouse.Options{ + Addr: []string{"127.0.0.1:9000"}, + Auth: clickhouse.Auth{ + Database: "default", + Username: "default", + Password: "", + }, + DialTimeout: time.Second, + Compression: &clickhouse.Compression{ + Method: clickhouse.CompressionLZ4, + }, + //Debug: true, + }) + ) + defer cancel() + assert.NoError(t, err) + // give it plenty of time before we conclusively assume deadlock + timeout := time.After(5 * time.Second) + done := make(chan bool) + go func() { + // should take 1s + rows, _ := conn.Query(ctx, "SELECT sleepEachRow(0.001) as Col1 FROM system.numbers LIMIT 1000 SETTINGS max_block_size=10;") + rows.Close() + done <- true + }() + + select { + case <-timeout: + t.Fatal("Close() deadlocked") + case <-done: + } +}