@@ -573,7 +573,6 @@ func TestTunnel_sendAgentUpdateReconnect(t *testing.T) {
573573 require .NoError (t , err )
574574
575575 // The new update only contains the new agent
576- mClock .AdvanceNext ()
577576 req = testutil .TryReceive (ctx , t , mgr .requests )
578577 require .Nil (t , req .msg .Rpc )
579578 peerUpdate := req .msg .GetPeerUpdate ()
@@ -695,14 +694,19 @@ func TestTunnel_sendAgentUpdateWorkspaceReconnect(t *testing.T) {
695694}
696695
697696//nolint:revive // t takes precedence
698- func setupTunnel (t * testing.T , ctx context.Context , client * fakeClient , mClock quartz.Clock ) (* Tunnel , * speaker [* ManagerMessage , * TunnelMessage , TunnelMessage ]) {
697+ func setupTunnel (t * testing.T , ctx context.Context , client * fakeClient , mClock * quartz.Mock ) (* Tunnel , * speaker [* ManagerMessage , * TunnelMessage , TunnelMessage ]) {
699698 mp , tp := net .Pipe ()
700699 t .Cleanup (func () { _ = mp .Close () })
701700 t .Cleanup (func () { _ = tp .Close () })
702701 logger := testutil .Logger (t )
702+ // We're creating a trap for the mClock to ensure that
703+ // AdvanceNext() is not called before the ticker is created.
704+ trap := mClock .Trap ().NewTicker ()
705+ defer trap .Close ()
703706
704707 var tun * Tunnel
705708 var mgr * speaker [* ManagerMessage , * TunnelMessage , TunnelMessage ]
709+
706710 errCh := make (chan error , 2 )
707711 go func () {
708712 tunnel , err := NewTunnel (ctx , logger .Named ("tunnel" ), tp , client , WithClock (mClock ))
@@ -719,6 +723,8 @@ func setupTunnel(t *testing.T, ctx context.Context, client *fakeClient, mClock q
719723 err = testutil .TryReceive (ctx , t , errCh )
720724 require .NoError (t , err )
721725 mgr .start ()
726+ // We're releasing the trap to allow the clock to advance the ticker.
727+ trap .MustWait (ctx ).Release ()
722728 return tun , mgr
723729}
724730
0 commit comments