-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flaky tests: Fix wrangler tests (#13568)
Signed-off-by: Manan Gupta <manan@planetscale.com>
- Loading branch information
1 parent
1e32824
commit 07221ad
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) | ||
} | ||
} | ||
} |