Skip to content

Commit

Permalink
Fix backported code in healthcheck_test
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljoos committed Jul 12, 2024
1 parent 1753623 commit 2fa8acb
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions go/vt/discovery/healthcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,11 @@ func init() {
}

func TestHealthCheckRace(t *testing.T) {
ctx := utils.LeakCheckContext(t)

// reset error counters
hcErrorCounters.ResetAll()
ts := memorytopo.NewServer(ctx, "cell")
ts := memorytopo.NewServer("cell")
defer ts.Close()
hc := createTestHc(ctx, ts)
hc := createTestHc(ts)
// close healthcheck
defer hc.Close()
tablet := createTestTablet(0, "cell", "a")
Expand All @@ -82,14 +80,17 @@ func TestHealthCheckRace(t *testing.T) {
Target: target,
Serving: true,

PrimaryTermStartTimestamp: 0,
RealtimeStats: &querypb.RealtimeStats{ReplicationLagSeconds: 1, CpuUsage: 0.5},
TabletExternallyReparentedTimestamp: 0,
RealtimeStats: &querypb.RealtimeStats{ReplicationLagSeconds: 1, CpuUsage: 0.5},
}

input := make(chan *querypb.StreamHealthResponse)
fc := createFakeConn(tablet, input)
fc.errCh = make(chan error)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

go func() {
ticker := time.NewTicker(10 * time.Millisecond)
defer ticker.Stop()
Expand Down Expand Up @@ -120,7 +121,7 @@ func TestHealthCheckRace(t *testing.T) {
case <-ctx.Done():
return
case <-ticker.C:
conn, err := hc.TabletConnection(context.Background(), tablet.Alias, target)
conn, err := hc.TabletConnection(tablet.Alias, target)

assert.NoError(t, err)
assert.NotNil(t, conn)
Expand Down Expand Up @@ -858,13 +859,11 @@ func TestRemoveTablet(t *testing.T) {
// During this time, operations like `RemoveTablet` should not lead
// to multiple tablets becoming valid targets for `PRIMARY`.
func TestRemoveTabletDuringExternalReparenting(t *testing.T) {
ctx := utils.LeakCheckContext(t)

// reset error counters
hcErrorCounters.ResetAll()
ts := memorytopo.NewServer(ctx, "cell")
ts := memorytopo.NewServer("cell")
defer ts.Close()
hc := createTestHc(ctx, ts)
hc := createTestHc(ts)
// close healthcheck
defer hc.Close()

Expand Down Expand Up @@ -905,26 +904,26 @@ func TestRemoveTabletDuringExternalReparenting(t *testing.T) {
Target: &querypb.Target{Keyspace: "k", Shard: "s", TabletType: topodatapb.TabletType_PRIMARY},
Serving: true,

PrimaryTermStartTimestamp: firstTabletPrimaryTermStartTimestamp,
RealtimeStats: &querypb.RealtimeStats{ReplicationLagSeconds: 0, CpuUsage: 0.5},
TabletExternallyReparentedTimestamp: firstTabletPrimaryTermStartTimestamp,
RealtimeStats: &querypb.RealtimeStats{ReplicationLagSeconds: 0, CpuUsage: 0.5},
}

secondTabletHealthStream <- &querypb.StreamHealthResponse{
TabletAlias: secondTablet.Alias,
Target: &querypb.Target{Keyspace: "k", Shard: "s", TabletType: topodatapb.TabletType_REPLICA},
Serving: true,

PrimaryTermStartTimestamp: 0,
RealtimeStats: &querypb.RealtimeStats{ReplicationLagSeconds: 1, CpuUsage: 0.5},
TabletExternallyReparentedTimestamp: 0,
RealtimeStats: &querypb.RealtimeStats{ReplicationLagSeconds: 1, CpuUsage: 0.5},
}

thirdTabletHealthStream <- &querypb.StreamHealthResponse{
TabletAlias: thirdTablet.Alias,
Target: &querypb.Target{Keyspace: "k", Shard: "s", TabletType: topodatapb.TabletType_REPLICA},
Serving: true,

PrimaryTermStartTimestamp: 0,
RealtimeStats: &querypb.RealtimeStats{ReplicationLagSeconds: 1, CpuUsage: 0.5},
TabletExternallyReparentedTimestamp: 0,
RealtimeStats: &querypb.RealtimeStats{ReplicationLagSeconds: 1, CpuUsage: 0.5},
}

<-resultChan
Expand All @@ -939,17 +938,17 @@ func TestRemoveTabletDuringExternalReparenting(t *testing.T) {
Target: &querypb.Target{Keyspace: "k", Shard: "s", TabletType: topodatapb.TabletType_PRIMARY},
Serving: true,

PrimaryTermStartTimestamp: firstTabletPrimaryTermStartTimestamp,
RealtimeStats: &querypb.RealtimeStats{ReplicationLagSeconds: 0, CpuUsage: 0.5},
TabletExternallyReparentedTimestamp: firstTabletPrimaryTermStartTimestamp,
RealtimeStats: &querypb.RealtimeStats{ReplicationLagSeconds: 0, CpuUsage: 0.5},
}

secondTabletHealthStream <- &querypb.StreamHealthResponse{
TabletAlias: secondTablet.Alias,
Target: &querypb.Target{Keyspace: "k", Shard: "s", TabletType: topodatapb.TabletType_PRIMARY},
Serving: true,

PrimaryTermStartTimestamp: secondTabletPrimaryTermStartTimestamp,
RealtimeStats: &querypb.RealtimeStats{ReplicationLagSeconds: 0, CpuUsage: 0.5},
TabletExternallyReparentedTimestamp: secondTabletPrimaryTermStartTimestamp,
RealtimeStats: &querypb.RealtimeStats{ReplicationLagSeconds: 0, CpuUsage: 0.5},
}

<-resultChan
Expand Down

0 comments on commit 2fa8acb

Please sign in to comment.