From e7303a5b27a3db25fcd2c4643a2b45147e40b86d Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Mon, 6 Nov 2023 15:06:14 +0100 Subject: [PATCH 1/3] Reduce wait time in test helpers Instead of waiting already before we check, immediately check and then start waiting if we need to. This avoids waiting neednessly which slows down tests. Also shorte the wait loop time to 100ms instead of 1s to speed things up even if we have to wait. Signed-off-by: Dirkjan Bussink --- go/test/endtoend/utils/utils.go | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/go/test/endtoend/utils/utils.go b/go/test/endtoend/utils/utils.go index fa270ba30a0..9e48c41059c 100644 --- a/go/test/endtoend/utils/utils.go +++ b/go/test/endtoend/utils/utils.go @@ -236,16 +236,17 @@ func WaitForAuthoritative(t *testing.T, ks, tbl string, readVSchema func() (*int case <-timeout: return fmt.Errorf("schema tracking didn't mark table t2 as authoritative until timeout") default: - time.Sleep(1 * time.Second) res, err := readVSchema() require.NoError(t, err, res) t2Map := getTableT2Map(res, ks, tbl) authoritative, fieldPresent := t2Map["column_list_authoritative"] if !fieldPresent { + time.Sleep(100 * time.Millisecond) continue } authoritativeBool, isBool := authoritative.(bool) if !isBool || !authoritativeBool { + time.Sleep(100 * time.Millisecond) continue } return nil @@ -262,18 +263,19 @@ func WaitForKsError(t *testing.T, vtgateProcess cluster.VtgateProcess, ks string t.Fatalf("schema tracking did not find error in '%s'", ks) return "" default: - time.Sleep(1 * time.Second) res, err := vtgateProcess.ReadVSchema() require.NoError(t, err, res) kss := convertToMap(*res)["keyspaces"] ksMap := convertToMap(convertToMap(kss)[ks]) ksErr, fieldPresent := ksMap["error"] if !fieldPresent { - break + time.Sleep(100 * time.Millisecond) + continue } errString, isErr := ksErr.(string) if !isErr { - break + time.Sleep(100 * time.Millisecond) + continue } return errString } @@ -288,25 +290,28 @@ func WaitForColumn(t *testing.T, vtgateProcess cluster.VtgateProcess, ks, tbl, c case <-timeout: return fmt.Errorf("schema tracking did not find column '%s' in table '%s'", col, tbl) default: - time.Sleep(1 * time.Second) res, err := vtgateProcess.ReadVSchema() require.NoError(t, err, res) t2Map := getTableT2Map(res, ks, tbl) authoritative, fieldPresent := t2Map["column_list_authoritative"] if !fieldPresent { - break + time.Sleep(100 * time.Millisecond) + continue } authoritativeBool, isBool := authoritative.(bool) if !isBool || !authoritativeBool { - break + time.Sleep(100 * time.Millisecond) + continue } colMap, exists := t2Map["columns"] if !exists { - break + time.Sleep(100 * time.Millisecond) + continue } colList, isSlice := colMap.([]interface{}) if !isSlice { - break + time.Sleep(100 * time.Millisecond) + continue } for _, c := range colList { colDef, isMap := c.(map[string]interface{}) @@ -317,6 +322,7 @@ func WaitForColumn(t *testing.T, vtgateProcess cluster.VtgateProcess, ks, tbl, c return nil } } + time.Sleep(100 * time.Millisecond) } } } @@ -330,7 +336,10 @@ func getTableT2Map(res *interface{}, ks, tbl string) map[string]interface{} { } func convertToMap(input interface{}) map[string]interface{} { - output := input.(map[string]interface{}) + output, ok := input.(map[string]interface{}) + if !ok { + return make(map[string]interface{}) + } return output } From 64124f7d0a4ceb02325283fdb60cc67d7a9b24b9 Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Wed, 15 Nov 2023 20:56:10 +0530 Subject: [PATCH 2/3] feat: wait for table to be dropped Signed-off-by: Manan Gupta --- go/test/endtoend/utils/utils.go | 22 +++++++++++++++++++ .../foreignkey/stress/fk_stress_test.go | 6 +++++ 2 files changed, 28 insertions(+) diff --git a/go/test/endtoend/utils/utils.go b/go/test/endtoend/utils/utils.go index 9e48c41059c..ae911b31704 100644 --- a/go/test/endtoend/utils/utils.go +++ b/go/test/endtoend/utils/utils.go @@ -282,6 +282,28 @@ func WaitForKsError(t *testing.T, vtgateProcess cluster.VtgateProcess, ks string } } +// WaitForTableDeletions waits for a table to be deleted +func WaitForTableDeletions(t *testing.T, vtgateProcess cluster.VtgateProcess, ks, tbl string) error { + timeout := time.After(60 * time.Second) + for { + select { + case <-timeout: + return fmt.Errorf("schema tracking still found the table '%s'", tbl) + default: + res, err := vtgateProcess.ReadVSchema() + require.NoError(t, err, res) + keyspacesMap := convertToMap(*res)["keyspaces"] + ksMap := convertToMap(keyspacesMap)[ks] + tablesMap := convertToMap(ksMap)["tables"] + _, isPresent := convertToMap(tablesMap)[tbl] + if !isPresent { + return nil + } + time.Sleep(100 * time.Millisecond) + } + } +} + // WaitForColumn waits for a table's column to be present func WaitForColumn(t *testing.T, vtgateProcess cluster.VtgateProcess, ks, tbl, col string) error { timeout := time.After(60 * time.Second) diff --git a/go/test/endtoend/vtgate/foreignkey/stress/fk_stress_test.go b/go/test/endtoend/vtgate/foreignkey/stress/fk_stress_test.go index e9f0602d235..4d3d9a98917 100644 --- a/go/test/endtoend/vtgate/foreignkey/stress/fk_stress_test.go +++ b/go/test/endtoend/vtgate/foreignkey/stress/fk_stress_test.go @@ -704,6 +704,12 @@ func createInitialSchema(t *testing.T, tcase *testCase) { require.NoError(t, err) } }) + t.Run("waiting for vschema deletions to apply", func(t *testing.T) { + for _, tableName := range tableNames { + err := utils.WaitForTableDeletions(t, clusterInstance.VtgateProcess, keyspaceName, tableName) + require.NoError(t, err) + } + }) t.Run("creating tables", func(t *testing.T) { // Create the stress tables var b strings.Builder From 9cd716fb0620a29575d8eece1f8d879cbd541505 Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Wed, 15 Nov 2023 21:11:48 +0530 Subject: [PATCH 3/3] feat: use a singe timeout for all the deletions Signed-off-by: Manan Gupta --- go/test/endtoend/utils/utils.go | 5 ++--- go/test/endtoend/vtgate/foreignkey/stress/fk_stress_test.go | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/go/test/endtoend/utils/utils.go b/go/test/endtoend/utils/utils.go index ae911b31704..0231cae7baf 100644 --- a/go/test/endtoend/utils/utils.go +++ b/go/test/endtoend/utils/utils.go @@ -283,11 +283,10 @@ func WaitForKsError(t *testing.T, vtgateProcess cluster.VtgateProcess, ks string } // WaitForTableDeletions waits for a table to be deleted -func WaitForTableDeletions(t *testing.T, vtgateProcess cluster.VtgateProcess, ks, tbl string) error { - timeout := time.After(60 * time.Second) +func WaitForTableDeletions(ctx context.Context, t *testing.T, vtgateProcess cluster.VtgateProcess, ks, tbl string) error { for { select { - case <-timeout: + case <-ctx.Done(): return fmt.Errorf("schema tracking still found the table '%s'", tbl) default: res, err := vtgateProcess.ReadVSchema() diff --git a/go/test/endtoend/vtgate/foreignkey/stress/fk_stress_test.go b/go/test/endtoend/vtgate/foreignkey/stress/fk_stress_test.go index 4d3d9a98917..91e64e67d1e 100644 --- a/go/test/endtoend/vtgate/foreignkey/stress/fk_stress_test.go +++ b/go/test/endtoend/vtgate/foreignkey/stress/fk_stress_test.go @@ -705,8 +705,10 @@ func createInitialSchema(t *testing.T, tcase *testCase) { } }) t.Run("waiting for vschema deletions to apply", func(t *testing.T) { + timeoutCtx, cancel := context.WithTimeout(ctx, 1*time.Minute) + defer cancel() for _, tableName := range tableNames { - err := utils.WaitForTableDeletions(t, clusterInstance.VtgateProcess, keyspaceName, tableName) + err := utils.WaitForTableDeletions(timeoutCtx, t, clusterInstance.VtgateProcess, keyspaceName, tableName) require.NoError(t, err) } })