Skip to content

Commit

Permalink
test: fix data race
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <[email protected]>
  • Loading branch information
GuptaManan100 committed Dec 22, 2024
1 parent 50f311a commit a7cbc4a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions go/vt/vttablet/tabletmanager/rpc_replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package tabletmanager

import (
"context"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -50,11 +51,11 @@ func TestWaitForGrantsToHaveApplied(t *testing.T) {
type demotePrimaryStallQS struct {
tabletserver.Controller
waitTime time.Duration
primaryStalled bool
primaryStalled atomic.Bool
}

func (d *demotePrimaryStallQS) SetDemotePrimaryStalled() {
d.primaryStalled = true
d.primaryStalled.Store(true)
}

func (d *demotePrimaryStallQS) IsServing() bool {
Expand All @@ -73,8 +74,7 @@ func TestDemotePrimaryStalled(t *testing.T) {

// Create a fake query service control to intercept calls from DemotePrimary function.
qsc := &demotePrimaryStallQS{
waitTime: 2 * time.Second,
primaryStalled: false,
waitTime: 2 * time.Second,
}
// Create a tablet manager with a replica type tablet.
tm := &TabletManager{
Expand All @@ -91,5 +91,5 @@ func TestDemotePrimaryStalled(t *testing.T) {
// We make IsServing stall for over 2 seconds, which is longer than 10 * remote operation timeout.
// This should cause the demote primary operation to be stalled.
tm.demotePrimary(context.Background(), false)
require.True(t, qsc.primaryStalled)
require.True(t, qsc.primaryStalled.Load())
}

0 comments on commit a7cbc4a

Please sign in to comment.