Skip to content

Commit

Permalink
improve test
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Vaillancourt <[email protected]>
  • Loading branch information
timvaillancourt committed Oct 2, 2024
1 parent 383cdcb commit 3483efc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 96 deletions.
76 changes: 3 additions & 73 deletions go/vt/vtctl/reparentutil/emergency_reparenter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1816,70 +1816,10 @@ func TestEmergencyReparenter_reparentShardLocked(t *testing.T) {
emergencyReparentOps: EmergencyReparentOptions{
ExpectedPrimaryAlias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 102,
},
},
tmc: &testutil.TabletManagerClient{
PopulateReparentJournalResults: map[string]error{
"zone1-0000000102": nil,
},
PromoteReplicaResults: map[string]struct {
Result string
Error error
}{
"zone1-0000000102": {
Result: "ok",
Error: nil,
},
},
SetReplicationSourceResults: map[string]error{
"zone1-0000000100": nil,
"zone1-0000000101": nil,
},
StopReplicationAndGetStatusResults: map[string]struct {
StopStatus *replicationdatapb.StopReplicationStatus
Error error
}{
"zone1-0000000100": {
StopStatus: &replicationdatapb.StopReplicationStatus{
Before: &replicationdatapb.Status{IoState: int32(replication.ReplicationStateRunning), SqlState: int32(replication.ReplicationStateRunning)},
After: &replicationdatapb.Status{
SourceUuid: "3E11FA47-71CA-11E1-9E33-C80AA9429562",
RelayLogPosition: "MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429562:1-21",
},
},
},
"zone1-0000000101": {
StopStatus: &replicationdatapb.StopReplicationStatus{
Before: &replicationdatapb.Status{IoState: int32(replication.ReplicationStateRunning), SqlState: int32(replication.ReplicationStateRunning)},
After: &replicationdatapb.Status{
SourceUuid: "3E11FA47-71CA-11E1-9E33-C80AA9429562",
RelayLogPosition: "MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429562:1-21",
},
},
},
"zone1-0000000102": {
StopStatus: &replicationdatapb.StopReplicationStatus{
Before: &replicationdatapb.Status{IoState: int32(replication.ReplicationStateRunning), SqlState: int32(replication.ReplicationStateRunning)},
After: &replicationdatapb.Status{
SourceUuid: "3E11FA47-71CA-11E1-9E33-C80AA9429562",
RelayLogPosition: "MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429562:1-26",
},
},
},
},
WaitForPositionResults: map[string]map[string]error{
"zone1-0000000100": {
"MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429562:1-21": nil,
},
"zone1-0000000101": {
"MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429562:1-21": nil,
},
"zone1-0000000102": {
"MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429562:1-26": nil,
},
Uid: 101,
},
},
tmc: &testutil.TabletManagerClient{},
shards: []*vtctldatapb.Shard{
{
Keyspace: "testkeyspace",
Expand Down Expand Up @@ -1912,22 +1852,12 @@ func TestEmergencyReparenter_reparentShardLocked(t *testing.T) {
Keyspace: "testkeyspace",
Shard: "-",
},
{
Alias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 102,
},
Type: topodatapb.TabletType_REPLICA,
Keyspace: "testkeyspace",
Shard: "-",
Hostname: "proposed primary",
},
},
keyspace: "testkeyspace",
shard: "-",
cells: []string{"zone1"},
shouldErr: true,
errShouldContain: "primary zone1-0000000100 is not equal to expected alias zone1-0000000102",
errShouldContain: "primary zone1-0000000100 is not equal to expected alias zone1-0000000101",
},
}

Expand Down
33 changes: 10 additions & 23 deletions go/vt/vtctl/reparentutil/planned_reparenter_flaky_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2518,8 +2518,9 @@ func TestPlannedReparenter_reparentShardLocked(t *testing.T) {
shard string
opts PlannedReparentOptions

shouldErr bool
expectedEvent *events.Reparent
shouldErr bool
errShouldContain string
expectedEvent *events.Reparent
}{
{
name: "success: current primary cannot be determined", // "Case (1)"
Expand Down Expand Up @@ -3299,23 +3300,7 @@ func TestPlannedReparenter_reparentShardLocked(t *testing.T) {
},
{
name: "expected primary mismatch",
tmc: &testutil.TabletManagerClient{
GetGlobalStatusVarsResults: map[string]struct {
Statuses map[string]string
Error error
}{
"zone1-0000000200": {
Statuses: map[string]string{
InnodbBufferPoolsDataVar: "123",
},
},
"zone1-0000000100": {
Statuses: map[string]string{
InnodbBufferPoolsDataVar: "123",
},
},
},
},
tmc: &testutil.TabletManagerClient{},
shards: []*vtctldatapb.Shard{
{
Keyspace: "testkeyspace",
Expand Down Expand Up @@ -3360,9 +3345,9 @@ func TestPlannedReparenter_reparentShardLocked(t *testing.T) {
Uid: 200,
},
},

shouldErr: true,
expectedEvent: nil,
shouldErr: true,
errShouldContain: "primary zone1-0000000100 is not equal to expected alias zone1-0000000200",
expectedEvent: nil,
},
}

Expand Down Expand Up @@ -3410,7 +3395,9 @@ func TestPlannedReparenter_reparentShardLocked(t *testing.T) {
err := pr.reparentShardLocked(ctx, tt.ev, tt.keyspace, tt.shard, tt.opts)
if tt.shouldErr {
assert.Error(t, err)

if tt.errShouldContain != "" {
assert.Contains(t, err.Error(), tt.errShouldContain)
}
return
}

Expand Down

0 comments on commit 3483efc

Please sign in to comment.