Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-15.0] Flaky tests: Fix wrangler tests (#13568) #13570

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions go/vt/wrangler/testlib/copy_schema_shard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ func copySchema(t *testing.T, useShardAsSource bool) {
if useShardAsSource {
source = "ks/-80"
}

// PrimaryAlias in the shard record is updated asynchronously, so we should wait for it to succeed.
waitForShardPrimary(t, wr, destinationPrimary.Tablet)

if err := vp.Run([]string{"CopySchemaShard", "--include-views", source, "ks/-40"}); err != nil {
t.Fatalf("CopySchemaShard failed: %v", err)
}
Expand Down
3 changes: 3 additions & 0 deletions go/vt/wrangler/testlib/external_reparent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,9 @@ func TestRPCTabletExternallyReparentedDemotesPrimaryToConfiguredTabletType(t *te
}
}

// PrimaryAlias in the shard record is updated asynchronously, so we should wait for it to succeed.
waitForShardPrimary(t, wr, newPrimary.Tablet)

shardInfo, err := ts.GetShard(context.Background(), newPrimary.Tablet.Keyspace, newPrimary.Tablet.Shard)
assert.NoError(t, err)

Expand Down
57 changes: 57 additions & 0 deletions go/vt/wrangler/testlib/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package testlib

import (
"context"
"testing"
"time"

"github.com/stretchr/testify/require"

topodatapb "vitess.io/vitess/go/vt/proto/topodata"
"vitess.io/vitess/go/vt/topo/topoproto"
"vitess.io/vitess/go/vt/wrangler"
)

// waitForTabletType waits for the given tablet type to be reached.
func waitForTabletType(t *testing.T, wr *wrangler.Wrangler, tabletAlias *topodatapb.TabletAlias, tabletType topodatapb.TabletType) {
timeout := time.After(15 * time.Second)
for {
tablet, err := wr.TopoServer().GetTablet(context.Background(), tabletAlias)
require.NoError(t, err)
if tablet.Type == tabletType {
return
}

select {
case <-timeout:
t.Fatalf("%s didn't reach the tablet type %v", topoproto.TabletAliasString(tabletAlias), tabletType.String())
return
default:
time.Sleep(100 * time.Millisecond)
}
}
}

// waitForShardPrimary waits for the shard record to be upto date such that it has the given primary.
func waitForShardPrimary(t *testing.T, wr *wrangler.Wrangler, primaryTablet *topodatapb.Tablet) {
timeout := time.After(15 * time.Second)
for {
si, err := wr.TopoServer().GetShard(context.Background(), primaryTablet.Keyspace, primaryTablet.Shard)
require.NoError(t, err)
if topoproto.TabletAliasEqual(si.PrimaryAlias, primaryTablet.Alias) {
return
}

select {
case <-timeout:
t.Fatalf("%s/%s didn't see the tablet %v become the primary, instead it is %v",
primaryTablet.Keyspace, primaryTablet.Shard,
topoproto.TabletAliasString(primaryTablet.Alias),
topoproto.TabletAliasString(si.PrimaryAlias),
)
return
default:
time.Sleep(100 * time.Millisecond)
}
}
}