@@ -2,6 +2,7 @@ package tailnet_test
2
2
3
3
import (
4
4
"context"
5
+ "io"
5
6
"net"
6
7
"net/netip"
7
8
"sync"
@@ -284,7 +285,7 @@ func TestInMemoryCoordination(t *testing.T) {
284
285
Times (1 ).Return (reqs , resps )
285
286
286
287
uut := tailnet .NewInMemoryCoordination (ctx , logger , clientID , agentID , mCoord , fConn )
287
- defer uut .Close ()
288
+ defer uut .Close (ctx )
288
289
289
290
coordinationTest (ctx , t , uut , fConn , reqs , resps , agentID )
290
291
@@ -336,16 +337,13 @@ func TestRemoteCoordination(t *testing.T) {
336
337
require .NoError (t , err )
337
338
338
339
uut := tailnet .NewRemoteCoordination (logger .Named ("coordination" ), protocol , fConn , agentID )
339
- defer uut .Close ()
340
+ defer uut .Close (ctx )
340
341
341
342
coordinationTest (ctx , t , uut , fConn , reqs , resps , agentID )
342
343
343
- select {
344
- case err := <- uut .Error ():
345
- require .ErrorContains (t , err , "stream terminated by sending close" )
346
- default :
347
- // OK!
348
- }
344
+ // Recv loop should be terminated by the server hanging up after Disconnect
345
+ err = testutil .RequireRecvCtx (ctx , t , uut .Error ())
346
+ require .ErrorIs (t , err , io .EOF )
349
347
}
350
348
351
349
func TestRemoteCoordination_SendsReadyForHandshake (t * testing.T ) {
@@ -388,7 +386,7 @@ func TestRemoteCoordination_SendsReadyForHandshake(t *testing.T) {
388
386
require .NoError (t , err )
389
387
390
388
uut := tailnet .NewRemoteCoordination (logger .Named ("coordination" ), protocol , fConn , uuid.UUID {})
391
- defer uut .Close ()
389
+ defer uut .Close (ctx )
392
390
393
391
nk , err := key .NewNode ().Public ().MarshalBinary ()
394
392
require .NoError (t , err )
@@ -411,14 +409,15 @@ func TestRemoteCoordination_SendsReadyForHandshake(t *testing.T) {
411
409
require .Len (t , rfh .ReadyForHandshake , 1 )
412
410
require .Equal (t , clientID [:], rfh .ReadyForHandshake [0 ].Id )
413
411
414
- require .NoError (t , uut .Close ())
412
+ go uut .Close (ctx )
413
+ dis := testutil .RequireRecvCtx (ctx , t , reqs )
414
+ require .NotNil (t , dis )
415
+ require .NotNil (t , dis .Disconnect )
416
+ close (resps )
415
417
416
- select {
417
- case err := <- uut .Error ():
418
- require .ErrorContains (t , err , "stream terminated by sending close" )
419
- default :
420
- // OK!
421
- }
418
+ // Recv loop should be terminated by the server hanging up after Disconnect
419
+ err = testutil .RequireRecvCtx (ctx , t , uut .Error ())
420
+ require .ErrorIs (t , err , io .EOF )
422
421
}
423
422
424
423
// coordinationTest tests that a coordination behaves correctly
@@ -464,13 +463,18 @@ func coordinationTest(
464
463
require .Len (t , fConn .updates [0 ], 1 )
465
464
require .Equal (t , agentID [:], fConn .updates [0 ][0 ].Id )
466
465
467
- err = uut .Close ()
468
- require .NoError (t , err )
469
- uut .Error ()
466
+ errCh := make (chan error , 1 )
467
+ go func () {
468
+ errCh <- uut .Close (ctx )
469
+ }()
470
470
471
471
// When we close, it should gracefully disconnect
472
472
req = testutil .RequireRecvCtx (ctx , t , reqs )
473
473
require .NotNil (t , req .Disconnect )
474
+ close (resps )
475
+
476
+ err = testutil .RequireRecvCtx (ctx , t , errCh )
477
+ require .NoError (t , err )
474
478
475
479
// It should set all peers lost on the coordinatee
476
480
require .Equal (t , 1 , fConn .setAllPeersLostCalls )
0 commit comments