@@ -336,14 +336,14 @@ func TestPGCoordinatorSingle_MissedHeartbeats(t *testing.T) {
336
336
t .Skip ("test only with postgres" )
337
337
}
338
338
store , ps := dbtestutil .NewDB (t )
339
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitSuperLong )
339
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitShort )
340
340
defer cancel ()
341
341
logger := slogtest .Make (t , nil ).Leveled (slog .LevelDebug )
342
342
mClock := clock .NewMock (t )
343
- nowTrap := mClock .Trap ().Now ("heartbeats" , "recvBeat" )
344
- defer nowTrap .Close ()
345
343
afTrap := mClock .Trap ().AfterFunc ("heartbeats" , "recvBeat" )
346
344
defer afTrap .Close ()
345
+ rstTrap := mClock .Trap ().TimerReset ("heartbeats" , "resetExpiryTimerWithLock" )
346
+ defer rstTrap .Close ()
347
347
348
348
coordinator , err := tailnet .NewTestPGCoord (ctx , logger , ps , store , mClock )
349
349
require .NoError (t , err )
@@ -370,7 +370,6 @@ func TestPGCoordinatorSingle_MissedHeartbeats(t *testing.T) {
370
370
}
371
371
372
372
fCoord2 .heartbeat ()
373
- nowTrap .MustWait (ctx ).Release ()
374
373
afTrap .MustWait (ctx ).Release () // heartbeat timeout started
375
374
376
375
fCoord2 .agentNode (agent .id , & agpl.Node {PreferredDERP : 12 })
@@ -383,30 +382,32 @@ func TestPGCoordinatorSingle_MissedHeartbeats(t *testing.T) {
383
382
id : uuid .New (),
384
383
}
385
384
fCoord3 .heartbeat ()
386
- nowTrap .MustWait (ctx ).Release ()
385
+ rstTrap .MustWait (ctx ).Release () // timeout gets reset
387
386
fCoord3 .agentNode (agent .id , & agpl.Node {PreferredDERP : 13 })
388
387
assertEventuallyHasDERPs (ctx , t , client , 13 )
389
388
390
389
// fCoord2 sends in a second heartbeat, one period later (on time)
391
- fCoord2 .heartbeat ()
392
- c := nowTrap .MustWait (ctx )
393
390
mClock .Advance (tailnet .HeartbeatPeriod ).MustWait (ctx )
394
- c .Release ()
391
+ fCoord2 .heartbeat ()
392
+ rstTrap .MustWait (ctx ).Release () // timeout gets reset
395
393
396
394
// when the fCoord3 misses enough heartbeats, the real coordinator should send an update with the
397
395
// node from fCoord2 for the agent.
398
396
mClock .Advance (tailnet .HeartbeatPeriod ).MustWait (ctx )
399
- mClock .Advance (tailnet .HeartbeatPeriod ).MustWait (ctx )
397
+ w := mClock .Advance (tailnet .HeartbeatPeriod )
398
+ rstTrap .MustWait (ctx ).Release ()
399
+ w .MustWait (ctx )
400
400
assertEventuallyHasDERPs (ctx , t , client , 12 )
401
401
402
402
// one more heartbeat period will result in fCoord2 being expired, which should cause us to
403
403
// revert to the original agent mapping
404
404
mClock .Advance (tailnet .HeartbeatPeriod ).MustWait (ctx )
405
+ // note that the timeout doesn't get reset because both fCoord2 and fCoord3 are expired
405
406
assertEventuallyHasDERPs (ctx , t , client , 10 )
406
407
407
408
// send fCoord3 heartbeat, which should trigger us to consider that mapping valid again.
408
409
fCoord3 .heartbeat ()
409
- nowTrap .MustWait (ctx ).Release ()
410
+ rstTrap .MustWait (ctx ).Release () // timeout gets reset
410
411
assertEventuallyHasDERPs (ctx , t , client , 13 )
411
412
412
413
err = agent .close ()
0 commit comments