forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release-15.0] Flaky tests: Fix wrangler tests (vitessio#13568) (vite…
…ssio#13570) Signed-off-by: Manan Gupta <manan@planetscale.com> Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
1e32824
commit a436abb
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |