From 5d7568d521bb820ce7a3b085f91dee3aa8ff35e7 Mon Sep 17 00:00:00 2001 From: "Eduardo J. Ortega U." <5791035+ejortegau@users.noreply.github.com> Date: Wed, 18 Dec 2024 17:20:10 +0100 Subject: [PATCH] Fix StateManager unit tests Signed-off-by: Eduardo J. Ortega U. <5791035+ejortegau@users.noreply.github.com> --- go/vt/vttablet/tabletserver/state_manager.go | 2 +- .../tabletserver/state_manager_test.go | 96 ++++++++++--------- 2 files changed, 52 insertions(+), 46 deletions(-) diff --git a/go/vt/vttablet/tabletserver/state_manager.go b/go/vt/vttablet/tabletserver/state_manager.go index 6e03cd7ab62..b069f2704e0 100644 --- a/go/vt/vttablet/tabletserver/state_manager.go +++ b/go/vt/vttablet/tabletserver/state_manager.go @@ -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() { diff --git a/go/vt/vttablet/tabletserver/state_manager_test.go b/go/vt/vttablet/tabletserver/state_manager_test.go index d06bbde4aea..1fcc6a734f3 100644 --- a/go/vt/vttablet/tabletserver/state_manager_test.go +++ b/go/vt/vttablet/tabletserver/state_manager_test.go @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -882,7 +882,7 @@ func (te *testQueryEngine) IsMySQLReachable() error { } func (te *testQueryEngine) Close() { - te.order = order.Add(1) + te.order = addOrder() te.state = testStateClosed } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 }