Skip to content

Commit 82bdf7f

Browse files
committed
fix: wait for agent to be up in TestAgent_Lifecycle/ShutdownScriptOnce
1 parent e5ce382 commit 82bdf7f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

agent/agent_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1650,8 +1650,10 @@ func TestAgent_Lifecycle(t *testing.T) {
16501650
t.Run("ShutdownScriptOnce", func(t *testing.T) {
16511651
t.Parallel()
16521652
logger := testutil.Logger(t)
1653+
ctx := testutil.Context(t, testutil.WaitMedium)
16531654
expected := "this-is-shutdown"
16541655
derpMap, _ := tailnettest.RunDERPAndSTUN(t)
1656+
statsCh := make(chan *proto.Stats, 50)
16551657

16561658
client := agenttest.NewClient(t,
16571659
logger,
@@ -1670,7 +1672,7 @@ func TestAgent_Lifecycle(t *testing.T) {
16701672
RunOnStop: true,
16711673
}},
16721674
},
1673-
make(chan *proto.Stats, 50),
1675+
statsCh,
16741676
tailnet.NewCoordinator(logger),
16751677
)
16761678
defer client.Close()
@@ -1695,6 +1697,11 @@ func TestAgent_Lifecycle(t *testing.T) {
16951697
return len(content) > 0 // something is in the startup log file
16961698
}, testutil.WaitShort, testutil.IntervalMedium)
16971699

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+
16981705
err := agent.Close()
16991706
require.NoError(t, err, "agent should be closed successfully")
17001707

0 commit comments

Comments
 (0)