diff --git a/agent/agentcontainers/api_test.go b/agent/agentcontainers/api_test.go index 9451461bb3215..eb75d5a62b661 100644 --- a/agent/agentcontainers/api_test.go +++ b/agent/agentcontainers/api_test.go @@ -358,15 +358,22 @@ func TestAPI(t *testing.T) { fakeCLI = &fakeContainerCLI{ listErr: firstErr, } + fWatcher = newFakeWatcher(t) ) api := agentcontainers.NewAPI(logger, + agentcontainers.WithWatcher(fWatcher), agentcontainers.WithClock(mClock), agentcontainers.WithContainerCLI(fakeCLI), ) api.Start() defer api.Close() + // The watcherLoop writes a log when it is initialized. + // We want to ensure this has happened before we start + // the test so that it does not intefere. + fWatcher.waitNext(ctx) + // Make sure the ticker function has been registered // before advancing the clock. tickerTrap.MustWait(ctx).MustRelease(ctx)