-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
utils.go
57 lines (50 loc) · 1.61 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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)
}
}
}