From 24ad0f268c65aaf9a8e8be40c4a1ecdb218e6d3c Mon Sep 17 00:00:00 2001 From: Stepan Burlakov Date: Tue, 13 Feb 2024 16:13:51 +0200 Subject: [PATCH] test: add long query runtime verification (#88) --- connection_common_integration_test.go | 31 +++++++++++++++++++++++++++ driver_integration_test.go | 13 ++--------- driver_integration_v0_test.go | 2 ++ 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/connection_common_integration_test.go b/connection_common_integration_test.go index dc215c8..15cb531 100644 --- a/connection_common_integration_test.go +++ b/connection_common_integration_test.go @@ -458,3 +458,34 @@ func TestConnectionPreparedStatement(t *testing.T) { } } } + +func TestLongQuery(t *testing.T) { + var maxValue = 0 + if v0Testing { + maxValue = 250000000000 + } else { + maxValue = 430000000000 + } + + finished_in := make(chan time.Duration, 1) + go func() { + started := time.Now() + db, err := sql.Open("firebolt", dsnSystemEngineMock) + if err != nil { + t.Errorf("failed unexpectedly with %v", err) + } + _, err = db.Query("SELECT checksum(*) FROM generate_series(1, ?)", maxValue) + if err != nil { + t.Errorf("failed to run long query %v", err) + } + finished_in <- time.Since(started) + }() + select { + case elapsed := <-finished_in: + if elapsed > 350*time.Minute { + t.Errorf("Expected execution time to be more than 350 sec but was %v sec", elapsed) + } + case <-time.After(10 * time.Minute): + t.Errorf("Long query didn't finish in 10 minutes") + } +} diff --git a/driver_integration_test.go b/driver_integration_test.go index 6c2027c..d8863b7 100644 --- a/driver_integration_test.go +++ b/driver_integration_test.go @@ -34,6 +34,8 @@ var ( clientMockWithAccount *ClientImpl ) +const v0Testing = false + // init populates mock variables and client for integration tests func init() { clientIdMock = os.Getenv("CLIENT_ID") @@ -271,17 +273,6 @@ func TestDriverSystemEngine(t *testing.T) { } } -func TestLongQuery(t *testing.T) { - db, err := sql.Open("firebolt", dsnSystemEngineMock) - if err != nil { - t.Errorf("failed unexpectedly with %v", err) - } - _, err = db.Query("SELECT checksum(*) FROM generate_series(1, 100000000000)") - if err != nil { - t.Errorf("failed to run long query %v", err) - } -} - func containsDatabase(rows *sql.Rows, databaseToFind string) (bool, error) { var databaseName, region, attachedEngines, createdOn, createdBy, errors string for rows.Next() { diff --git a/driver_integration_v0_test.go b/driver_integration_v0_test.go index 3a0575c..dcb8534 100644 --- a/driver_integration_v0_test.go +++ b/driver_integration_v0_test.go @@ -35,6 +35,8 @@ var ( clientMock *ClientImplV0 ) +const v0Testing = true + // init populates mock variables and client for integration tests func init() { usernameMock = os.Getenv("USER_NAME")