From dff095748af3d26c9b74eec466bf008a698dee14 Mon Sep 17 00:00:00 2001 From: "vitess-bot[bot]" <108069721+vitess-bot[bot]@users.noreply.github.com> Date: Wed, 26 Jul 2023 00:02:17 +0530 Subject: [PATCH] [release-16.0] fix TestQueryTimeoutWithTables flaky test (#13579) (#13585) Signed-off-by: Harshit Gangal Co-authored-by: Harshit Gangal --- .../endtoend/vtgate/queries/misc/main_test.go | 6 ++- .../endtoend/vtgate/queries/misc/misc_test.go | 39 ++++++------------- 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/go/test/endtoend/vtgate/queries/misc/main_test.go b/go/test/endtoend/vtgate/queries/misc/main_test.go index de2d00219b6..d71dc55ef46 100644 --- a/go/test/endtoend/vtgate/queries/misc/main_test.go +++ b/go/test/endtoend/vtgate/queries/misc/main_test.go @@ -61,7 +61,8 @@ func TestMain(m *testing.M) { return 1 } - clusterInstance.VtTabletExtraArgs = append(clusterInstance.VtTabletExtraArgs, "--queryserver-config-max-result-size", "1000000", + clusterInstance.VtTabletExtraArgs = append(clusterInstance.VtTabletExtraArgs, + "--queryserver-config-max-result-size", "1000000", "--queryserver-config-query-timeout", "200", "--queryserver-config-query-pool-timeout", "200") // Start Unsharded keyspace @@ -85,7 +86,8 @@ func TestMain(m *testing.M) { return 1 } - clusterInstance.VtGateExtraArgs = append(clusterInstance.VtGateExtraArgs, "--enable_system_settings=true", "--query-timeout=100") + clusterInstance.VtGateExtraArgs = append(clusterInstance.VtGateExtraArgs, + "--query-timeout", "100") // Start vtgate err = clusterInstance.StartVtgate() if err != nil { diff --git a/go/test/endtoend/vtgate/queries/misc/misc_test.go b/go/test/endtoend/vtgate/queries/misc/misc_test.go index 39b047015a7..2c8aece59fb 100644 --- a/go/test/endtoend/vtgate/queries/misc/misc_test.go +++ b/go/test/endtoend/vtgate/queries/misc/misc_test.go @@ -101,21 +101,21 @@ func TestQueryTimeoutWithDual(t *testing.T) { mcmp, closer := start(t) defer closer() - _, err := utils.ExecAllowError(t, mcmp.VtConn, "select /*vt+ PLANNER=gen4 */ sleep(0.04) from dual") + _, err := utils.ExecAllowError(t, mcmp.VtConn, "select sleep(0.04) from dual") assert.NoError(t, err) - _, err = utils.ExecAllowError(t, mcmp.VtConn, "select /*vt+ PLANNER=gen4 */ sleep(0.24) from dual") + _, err = utils.ExecAllowError(t, mcmp.VtConn, "select sleep(0.24) from dual") assert.Error(t, err) _, err = utils.ExecAllowError(t, mcmp.VtConn, "set @@session.query_timeout=20") require.NoError(t, err) - _, err = utils.ExecAllowError(t, mcmp.VtConn, "select /*vt+ PLANNER=gen4 */ sleep(0.04) from dual") + _, err = utils.ExecAllowError(t, mcmp.VtConn, "select sleep(0.04) from dual") assert.Error(t, err) - _, err = utils.ExecAllowError(t, mcmp.VtConn, "select /*vt+ PLANNER=gen4 */ sleep(0.01) from dual") + _, err = utils.ExecAllowError(t, mcmp.VtConn, "select sleep(0.01) from dual") assert.NoError(t, err) - _, err = utils.ExecAllowError(t, mcmp.VtConn, "select /*vt+ PLANNER=gen4 QUERY_TIMEOUT_MS=500 */ sleep(0.24) from dual") + _, err = utils.ExecAllowError(t, mcmp.VtConn, "select /*vt+ QUERY_TIMEOUT_MS=500 */ sleep(0.24) from dual") assert.NoError(t, err) - _, err = utils.ExecAllowError(t, mcmp.VtConn, "select /*vt+ PLANNER=gen4 QUERY_TIMEOUT_MS=10 */ sleep(0.04) from dual") + _, err = utils.ExecAllowError(t, mcmp.VtConn, "select /*vt+ QUERY_TIMEOUT_MS=10 */ sleep(0.04) from dual") assert.Error(t, err) - _, err = utils.ExecAllowError(t, mcmp.VtConn, "select /*vt+ PLANNER=gen4 QUERY_TIMEOUT_MS=15 */ sleep(0.001) from dual") + _, err = utils.ExecAllowError(t, mcmp.VtConn, "select /*vt+ QUERY_TIMEOUT_MS=15 */ sleep(0.001) from dual") assert.NoError(t, err) } @@ -139,28 +139,11 @@ func TestQueryTimeoutWithTables(t *testing.T) { assert.Contains(t, err.Error(), "(errno 1317) (sqlstate 70100)") // sharded - for i := 0; i < 300000; i += 1000 { - var str strings.Builder - for j := 1; j <= 1000; j++ { - if j == 1 { - str.WriteString(fmt.Sprintf("(%d)", i*1000+j)) - continue - } - str.WriteString(fmt.Sprintf(",(%d)", i*1000+j)) - } - utils.Exec(t, mcmp.VtConn, fmt.Sprintf("insert /*vt+ QUERY_TIMEOUT_MS=1000 */ into t1(id1) values %s", str.String())) - } - // too much data added in the loop, do drop and recreate the table. - defer func() { - mcmp.Exec("drop table t1") - mcmp.Exec(schemaSQL) - }() + utils.Exec(t, mcmp.VtConn, "insert /*vt+ QUERY_TIMEOUT_MS=1000 */ into ks_misc.t1(id1, id2) values (1,2),(2,4),(3,6),(4,8),(5,10)") - utils.Exec(t, mcmp.VtConn, "select count(*) from t1 where id1 > 31") - utils.Exec(t, mcmp.VtConn, "select /*vt+ PLANNER=gen4 QUERY_TIMEOUT_MS=100 */ count(*) from t1 where id1 > 31") - - // the query usually takes more than 5ms to return. So this should fail. - _, err = utils.ExecAllowError(t, mcmp.VtConn, "select /*vt+ PLANNER=gen4 QUERY_TIMEOUT_MS=1 */ count(*) from t1 where id1 > 31") + // sleep take in seconds, so 0.1 is 100ms + utils.Exec(t, mcmp.VtConn, "select /*vt+ PLANNER=gen4 QUERY_TIMEOUT_MS=500 */ sleep(0.1) from t1 where id1 = 1") + _, err = utils.ExecAllowError(t, mcmp.VtConn, "select /*vt+ PLANNER=gen4 QUERY_TIMEOUT_MS=20 */ sleep(0.1) from t1 where id1 = 1") require.Error(t, err) assert.Contains(t, err.Error(), "context deadline exceeded") assert.Contains(t, err.Error(), "(errno 1317) (sqlstate 70100)")