Skip to content

Commit

Permalink
addressed review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal committed Nov 20, 2023
1 parent 50b5fea commit 10a7424
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 35 deletions.
39 changes: 21 additions & 18 deletions go/test/endtoend/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,21 @@ func WaitForAuthoritative(t *testing.T, ks, tbl string, readVSchema func() (*int
}

// WaitForKsError waits for the ks error field to be populated and returns it.
func WaitForKsError(t *testing.T, vtgateProcess cluster.VtgateProcess, ks string) string {
var errString string
WaitForVschemaCondition(t, vtgateProcess, ks, func(t *testing.T, keyspace map[string]interface{}) bool {
ksErr, fieldPresent := keyspace["error"]
if !fieldPresent {
return false
}
var ok bool
errString, ok = ksErr.(string)
return ok
})
return errString
}

// WaitForVschemaCondition waits for the condition to be true
func WaitForVschemaCondition(t *testing.T, vtgateProcess cluster.VtgateProcess, ks string, conditionMet func(t *testing.T, keyspace map[string]interface{}) bool) {
timeout := time.After(60 * time.Second)
for {
Expand All @@ -275,24 +290,12 @@ func WaitForVschemaCondition(t *testing.T, vtgateProcess cluster.VtgateProcess,
}

// WaitForTableDeletions waits for a table to be deleted
func WaitForTableDeletions(ctx context.Context, t *testing.T, vtgateProcess cluster.VtgateProcess, ks, tbl string) error {
for {
select {
case <-ctx.Done():
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)
}
}
func WaitForTableDeletions(ctx context.Context, t *testing.T, vtgateProcess cluster.VtgateProcess, ks, tbl string) {
WaitForVschemaCondition(t, vtgateProcess, ks, func(t *testing.T, keyspace map[string]interface{}) bool {
tablesMap := keyspace["tables"]
_, isPresent := convertToMap(tablesMap)[tbl]
return !isPresent
})
}

// WaitForColumn waits for a table's column to be present
Expand Down
17 changes: 2 additions & 15 deletions go/test/endtoend/vtgate/foreignkey/fk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -979,22 +979,9 @@ func TestCyclicFks(t *testing.T) {
// Create a cyclic foreign key constraint.
utils.Exec(t, mcmp.VtConn, "alter table fk_t10 add constraint test_cyclic_fks foreign key (col) references fk_t12 (col) on delete cascade on update cascade")

matchKsError := func(t *testing.T, keyspace map[string]interface{}) bool {
ksErr, fieldPresent := keyspace["error"]
if !fieldPresent {
return false
}
errString, isErr := ksErr.(string)
if !isErr {
return false
}
// Make sure Vschema has the error for cyclic foreign keys.
assert.Contains(t, errString, "VT09019: keyspace 'uks' has cyclic foreign keys")
return true
}

// Wait for schema-tracking to be complete.
utils.WaitForVschemaCondition(t, clusterInstance.VtgateProcess, unshardedKs, matchKsError)
errString := utils.WaitForKsError(t, clusterInstance.VtgateProcess, unshardedKs)
assert.Contains(t, errString, "VT09019: keyspace 'uks' has cyclic foreign keys")

// Ensure that the Vitess database is originally empty
ensureDatabaseState(t, mcmp.VtConn, true)
Expand Down
3 changes: 1 addition & 2 deletions go/test/endtoend/vtgate/foreignkey/stress/fk_stress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,7 @@ func createInitialSchema(t *testing.T, tcase *testCase) {
timeoutCtx, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel()
for _, tableName := range tableNames {
err := utils.WaitForTableDeletions(timeoutCtx, t, clusterInstance.VtgateProcess, keyspaceName, tableName)
require.NoError(t, err)
utils.WaitForTableDeletions(timeoutCtx, t, clusterInstance.VtgateProcess, keyspaceName, tableName)
}
})
t.Run("creating tables", func(t *testing.T) {
Expand Down

0 comments on commit 10a7424

Please sign in to comment.