@@ -1650,8 +1650,10 @@ func TestAgent_Lifecycle(t *testing.T) {
1650
1650
t .Run ("ShutdownScriptOnce" , func (t * testing.T ) {
1651
1651
t .Parallel ()
1652
1652
logger := testutil .Logger (t )
1653
+ ctx := testutil .Context (t , testutil .WaitMedium )
1653
1654
expected := "this-is-shutdown"
1654
1655
derpMap , _ := tailnettest .RunDERPAndSTUN (t )
1656
+ statsCh := make (chan * proto.Stats , 50 )
1655
1657
1656
1658
client := agenttest .NewClient (t ,
1657
1659
logger ,
@@ -1670,7 +1672,7 @@ func TestAgent_Lifecycle(t *testing.T) {
1670
1672
RunOnStop : true ,
1671
1673
}},
1672
1674
},
1673
- make ( chan * proto. Stats , 50 ) ,
1675
+ statsCh ,
1674
1676
tailnet .NewCoordinator (logger ),
1675
1677
)
1676
1678
defer client .Close ()
@@ -1695,6 +1697,11 @@ func TestAgent_Lifecycle(t *testing.T) {
1695
1697
return len (content ) > 0 // something is in the startup log file
1696
1698
}, testutil .WaitShort , testutil .IntervalMedium )
1697
1699
1700
+ // In order to avoid shutting down the agent before it is fully started and triggering
1701
+ // errors, we'll wait until the agent is fully up. It's a bit hokey, but among the last things the agent starts
1702
+ // is the stats reporting, so getting a stats report is a good indication the agent is fully up.
1703
+ _ = testutil .RequireRecvCtx (ctx , t , statsCh )
1704
+
1698
1705
err := agent .Close ()
1699
1706
require .NoError (t , err , "agent should be closed successfully" )
1700
1707
0 commit comments