Skip to content

Commit

Permalink
fix test race
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
  • Loading branch information
shlomi-noach committed Aug 8, 2024
1 parent 4676761 commit ad4d87e
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions go/vt/vttablet/tabletserver/throttle/throttler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1495,10 +1495,14 @@ func TestProbesWhileOperating(t *testing.T) {
})

t.Run("metrics", func(t *testing.T) {
assert.Len(t, throttler.inventory.TabletMetrics, 3) // 1 self tablet + 2 shard tablets
assert.Contains(t, throttler.inventory.TabletMetrics, "", "TabletMetrics: %+v", throttler.inventory.TabletMetrics) // primary self identifies with empty alias
assert.Contains(t, throttler.inventory.TabletMetrics, "fakezone1-0000000101", "TabletMetrics: %+v", throttler.inventory.TabletMetrics)
assert.Contains(t, throttler.inventory.TabletMetrics, "fakezone2-0000000102", "TabletMetrics: %+v", throttler.inventory.TabletMetrics)
var results base.TabletResultMap
<-runSerialFunction(t, ctx, throttler, func(ctx context.Context) {
results = maps.Clone(throttler.inventory.TabletMetrics)
})
assert.Len(t, results, 3) // 1 self tablet + 2 shard tablets
assert.Contains(t, results, "", "TabletMetrics: %+v", results) // primary self identifies with empty alias
assert.Contains(t, results, "fakezone1-0000000101", "TabletMetrics: %+v", results)
assert.Contains(t, results, "fakezone2-0000000102", "TabletMetrics: %+v", results)
})

t.Run("no REPLICA probes", func(t *testing.T) {
Expand All @@ -1511,9 +1515,13 @@ func TestProbesWhileOperating(t *testing.T) {
ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()
for {
if len(throttler.inventory.TabletMetrics) == 1 {
var results base.TabletResultMap
<-runSerialFunction(t, ctx, throttler, func(ctx context.Context) {
results = maps.Clone(throttler.inventory.TabletMetrics)
})
if len(results) == 1 {
// That's what we were waiting for. Good.
assert.Contains(t, throttler.inventory.TabletMetrics, "", "TabletMetrics: %+v", throttler.inventory.TabletMetrics) // primary self identifies with empty alias
assert.Contains(t, results, "", "TabletMetrics: %+v", results) // primary self identifies with empty alias
return
}

Expand All @@ -1532,7 +1540,11 @@ func TestProbesWhileOperating(t *testing.T) {
ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()
for {
if len(throttler.inventory.TabletMetrics) == 3 {
var results base.TabletResultMap
<-runSerialFunction(t, ctx, throttler, func(ctx context.Context) {
results = maps.Clone(throttler.inventory.TabletMetrics)
})
if len(results) == 3 {
// That's what we were waiting for. Good.
return
}
Expand Down

0 comments on commit ad4d87e

Please sign in to comment.