Skip to content

Commit

Permalink
test: add a test for demote primary blocked field
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <[email protected]>
  • Loading branch information
GuptaManan100 committed Nov 27, 2024
1 parent 0239888 commit f3cab23
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions go/vt/vttablet/tabletserver/state_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,42 @@ func TestStateManagerNotify(t *testing.T) {
sm.StopService()
}

func TestDemotePrimaryBlocked(t *testing.T) {
sm := newTestStateManager()
defer sm.StopService()
err := sm.SetServingType(topodatapb.TabletType_PRIMARY, testNow, StateServing, "")
require.NoError(t, err)
// Stopping the ticker so that we don't get unexpected health streams.
sm.hcticks.Stop()

ch := make(chan *querypb.StreamHealthResponse, 5)
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
err := sm.hs.Stream(context.Background(), func(shr *querypb.StreamHealthResponse) error {
ch <- shr
return nil
})
assert.Contains(t, err.Error(), "tabletserver is shutdown")
}()
defer wg.Wait()

// Send a broadcast message and check we have no error there.
sm.Broadcast()
gotshr := <-ch
require.Empty(t, gotshr.RealtimeStats.HealthError)

// If demote primary is blocked, then we should get an error.
sm.demotePrimaryBlocked = true
sm.Broadcast()
gotshr = <-ch
require.EqualValues(t, "Demoting primary is blocked", gotshr.RealtimeStats.HealthError)

// Stop the state manager.
sm.StopService()
}

func TestRefreshReplHealthLocked(t *testing.T) {
sm := newTestStateManager()
defer sm.StopService()
Expand Down

0 comments on commit f3cab23

Please sign in to comment.