Skip to content

Commit

Permalink
test: fix test to also send a higher primary timestamp
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <[email protected]>
  • Loading branch information
GuptaManan100 authored and arthurschreiber committed Nov 8, 2024
1 parent 0c87ea7 commit 517f519
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions go/vt/discovery/fake_healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,21 @@ func (fhc *FakeHealthCheck) SetTabletType(tablet *topodatapb.Tablet, tabletType
item.ts.Target.TabletType = tabletType
}

// SetPrimaryTimestamp sets the primary timestamp for the given tablet
func (fhc *FakeHealthCheck) SetPrimaryTimestamp(tablet *topodatapb.Tablet, timestamp int64) {
if fhc.ch == nil {
return
}
fhc.mu.Lock()
defer fhc.mu.Unlock()
key := TabletToMapKey(tablet)
item, isPresent := fhc.items[key]
if !isPresent {
return
}
item.ts.PrimaryTermStartTime = timestamp
}

// Unsubscribe is not implemented.
func (fhc *FakeHealthCheck) Unsubscribe(c chan *TabletHealth) {
}
Expand Down
3 changes: 2 additions & 1 deletion go/vt/vtgate/tabletgateway_flaky_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ func TestGatewayBufferingWhileReparenting(t *testing.T) {
hc.SetTabletType(primaryTablet, topodatapb.TabletType_REPLICA)
hc.Broadcast(primaryTablet)
hc.SetTabletType(replicaTablet, topodatapb.TabletType_PRIMARY)
hc.SetPrimaryTimestamp(replicaTablet, 100) // We set a higher timestamp than before to simulate a PRS.
hc.SetServing(replicaTablet, true)
hc.Broadcast(replicaTablet)

Expand All @@ -245,7 +246,7 @@ outer:
require.Fail(t, "timed out - could not verify the new primary")
case <-time.After(10 * time.Millisecond):
newPrimary, shouldBuffer := tg.kev.ShouldStartBufferingForTarget(ctx, target)
if newPrimary != nil && newPrimary.Uid == 1 && !shouldBuffer {
if newPrimary != nil && newPrimary.Uid == replicaTablet.Alias.Uid && !shouldBuffer {
break outer
}
}
Expand Down

0 comments on commit 517f519

Please sign in to comment.