Skip to content

Commit

Permalink
Fix StateManager unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo J. Ortega U. <5791035+ejortegau@users.noreply.github.com>
  • Loading branch information
ejortegau committed Dec 18, 2024
1 parent 46155c3 commit 5d7568d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 46 deletions.
2 changes: 1 addition & 1 deletion go/vt/vttablet/tabletserver/state_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ func (sm *stateManager) connect(tabletType topodatapb.TabletType, serving bool)
if err := sm.qe.Open(); err != nil {
return err
}
return sm.txThrottler.Open()
return nil
}

func (sm *stateManager) unserveCommon() {
Expand Down
96 changes: 51 additions & 45 deletions go/vt/vttablet/tabletserver/state_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ func TestStateManagerServePrimary(t *testing.T) {
verifySubcomponent(t, 2, sm.se, testStateOpen)
verifySubcomponent(t, 3, sm.vstreamer, testStateOpen)
verifySubcomponent(t, 4, sm.qe, testStateOpen)
verifySubcomponent(t, 6, sm.rt, testStatePrimary)
verifySubcomponent(t, 7, sm.txThrottler, testStatePrimary)
verifySubcomponent(t, 8, sm.tracker, testStateOpen)
verifySubcomponent(t, 9, sm.te, testStatePrimary)
verifySubcomponent(t, 10, sm.messager, testStateOpen)
verifySubcomponent(t, 11, sm.throttler, testStateOpen)
verifySubcomponent(t, 12, sm.tableGC, testStateOpen)
verifySubcomponent(t, 13, sm.ddle, testStateOpen)
verifySubcomponent(t, 5, sm.rt, testStatePrimary)
verifySubcomponent(t, 6, sm.txThrottler, testStatePrimary)
verifySubcomponent(t, 7, sm.tracker, testStateOpen)
verifySubcomponent(t, 8, sm.te, testStatePrimary)
verifySubcomponent(t, 9, sm.messager, testStateOpen)
verifySubcomponent(t, 10, sm.throttler, testStateOpen)
verifySubcomponent(t, 11, sm.tableGC, testStateOpen)
verifySubcomponent(t, 12, sm.ddle, testStateOpen)

assert.False(t, sm.se.(*testSchemaEngine).nonPrimary)
assert.True(t, sm.se.(*testSchemaEngine).ensureCalled)
Expand All @@ -108,14 +108,14 @@ func TestStateManagerServeNonPrimary(t *testing.T) {
verifySubcomponent(t, 4, sm.tracker, testStateClosed)
assert.True(t, sm.se.(*testSchemaEngine).nonPrimary)

verifySubcomponent(t, 5, sm.txThrottler, testStateNonPrimary)
verifySubcomponent(t, 6, sm.se, testStateOpen)
verifySubcomponent(t, 7, sm.vstreamer, testStateOpen)
verifySubcomponent(t, 8, sm.qe, testStateOpen)
verifySubcomponent(t, 9, sm.txThrottler, testStateOpen)
verifySubcomponent(t, 10, sm.te, testStateNonPrimary)
verifySubcomponent(t, 11, sm.rt, testStateNonPrimary)
verifySubcomponent(t, 12, sm.watcher, testStateOpen)
verifySubcomponent(t, 13, sm.throttler, testStateOpen)
verifySubcomponent(t, 9, sm.te, testStateNonPrimary)
verifySubcomponent(t, 10, sm.rt, testStateNonPrimary)
verifySubcomponent(t, 11, sm.watcher, testStateOpen)
verifySubcomponent(t, 12, sm.throttler, testStateOpen)

assert.Equal(t, topodatapb.TabletType_REPLICA, sm.target.TabletType)
assert.Equal(t, StateServing, sm.state)
Expand All @@ -139,8 +139,8 @@ func TestStateManagerUnservePrimary(t *testing.T) {
verifySubcomponent(t, 9, sm.vstreamer, testStateOpen)
verifySubcomponent(t, 10, sm.qe, testStateOpen)

verifySubcomponent(t, 12, sm.rt, testStatePrimary)
verifySubcomponent(t, 13, sm.txThrottler, testStatePrimary)
verifySubcomponent(t, 11, sm.rt, testStatePrimary)
verifySubcomponent(t, 12, sm.txThrottler, testStatePrimary)

assert.Equal(t, topodatapb.TabletType_PRIMARY, sm.target.TabletType)
assert.Equal(t, StateNotServing, sm.state)
Expand All @@ -161,10 +161,10 @@ func TestStateManagerUnserveNonPrimary(t *testing.T) {
verifySubcomponent(t, 6, sm.tracker, testStateClosed)
assert.True(t, sm.se.(*testSchemaEngine).nonPrimary)

verifySubcomponent(t, 7, sm.se, testStateOpen)
verifySubcomponent(t, 8, sm.vstreamer, testStateOpen)
verifySubcomponent(t, 9, sm.qe, testStateOpen)
verifySubcomponent(t, 10, sm.txThrottler, testStateNonPrimary)
verifySubcomponent(t, 7, sm.txThrottler, testStateNonPrimary)
verifySubcomponent(t, 8, sm.se, testStateOpen)
verifySubcomponent(t, 9, sm.vstreamer, testStateOpen)
verifySubcomponent(t, 10, sm.qe, testStateOpen)

verifySubcomponent(t, 11, sm.rt, testStateNonPrimary)
verifySubcomponent(t, 12, sm.watcher, testStateOpen)
Expand Down Expand Up @@ -299,10 +299,10 @@ func TestStateManagerSetServingTypeNoChange(t *testing.T) {
verifySubcomponent(t, 4, sm.tracker, testStateClosed)
assert.True(t, sm.se.(*testSchemaEngine).nonPrimary)

verifySubcomponent(t, 5, sm.se, testStateOpen)
verifySubcomponent(t, 6, sm.vstreamer, testStateOpen)
verifySubcomponent(t, 7, sm.qe, testStateOpen)
verifySubcomponent(t, 8, sm.txThrottler, testStateOpen)
verifySubcomponent(t, 5, sm.txThrottler, testStateNonPrimary)
verifySubcomponent(t, 6, sm.se, testStateOpen)
verifySubcomponent(t, 7, sm.vstreamer, testStateOpen)
verifySubcomponent(t, 8, sm.qe, testStateOpen)
verifySubcomponent(t, 9, sm.te, testStateNonPrimary)
verifySubcomponent(t, 10, sm.rt, testStateNonPrimary)
verifySubcomponent(t, 11, sm.watcher, testStateOpen)
Expand Down Expand Up @@ -818,7 +818,7 @@ func (te *testSchemaEngine) EnsureConnectionAndDB(topodatapb.TabletType, bool) e
}

func (te *testSchemaEngine) Open() error {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateOpen
return nil
}
Expand All @@ -832,7 +832,7 @@ func (te *testSchemaEngine) MakePrimary(serving bool) {
}

func (te *testSchemaEngine) Close() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateClosed
}

Expand All @@ -843,17 +843,17 @@ type testReplTracker struct {
}

func (te *testReplTracker) MakePrimary() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStatePrimary
}

func (te *testReplTracker) MakeNonPrimary() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateNonPrimary
}

func (te *testReplTracker) Close() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateClosed
}

Expand All @@ -868,7 +868,7 @@ type testQueryEngine struct {
}

func (te *testQueryEngine) Open() error {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateOpen
return nil
}
Expand All @@ -882,7 +882,7 @@ func (te *testQueryEngine) IsMySQLReachable() error {
}

func (te *testQueryEngine) Close() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateClosed
}

Expand All @@ -891,17 +891,17 @@ type testTxEngine struct {
}

func (te *testTxEngine) AcceptReadWrite() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStatePrimary
}

func (te *testTxEngine) AcceptReadOnly() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateNonPrimary
}

func (te *testTxEngine) Close() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateClosed
}

Expand All @@ -912,12 +912,12 @@ type testSubcomponent struct {
}

func (te *testSubcomponent) Open() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateOpen
}

func (te *testSubcomponent) Close() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateClosed
}

Expand All @@ -926,38 +926,44 @@ type testTxThrottler struct {
}

func (te *testTxThrottler) Open() error {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateOpen
return nil
}

func (te *testTxThrottler) Close() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateClosed
}

func (te *testTxThrottler) MakePrimary() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStatePrimary
}

func (te *testTxThrottler) MakeNonPrimary() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateNonPrimary
}

func addOrder() int64 {
newVal := order.Add(1)

return newVal
}

type testOnlineDDLExecutor struct {
testOrderState
}

func (te *testOnlineDDLExecutor) Open() error {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateOpen
return nil
}

func (te *testOnlineDDLExecutor) Close() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateClosed
}

Expand All @@ -966,13 +972,13 @@ type testLagThrottler struct {
}

func (te *testLagThrottler) Open() error {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateOpen
return nil
}

func (te *testLagThrottler) Close() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateClosed
}

Expand All @@ -981,12 +987,12 @@ type testTableGC struct {
}

func (te *testTableGC) Open() error {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateOpen
return nil
}

func (te *testTableGC) Close() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateClosed
}

0 comments on commit 5d7568d

Please sign in to comment.