@@ -2883,8 +2883,12 @@ func TestAPI(t *testing.T) {
28832883Op :fsnotify .Write ,
28842884})
28852885
2886- err = api .RefreshContainers (ctx )
2887- require .NoError (t ,err )
2886+ require .Eventuallyf (t ,func ()bool {
2887+ err = api .RefreshContainers (ctx )
2888+ require .NoError (t ,err )
2889+
2890+ return len (fakeSAC .agents )== 1
2891+ },testutil .WaitShort ,testutil .IntervalFast ,"subagent should be created after config change" )
28882892
28892893t .Log ("Phase 2: Cont, waiting for sub agent to exit" )
28902894exitSubAgentOnce .Do (func () {
@@ -2919,8 +2923,12 @@ func TestAPI(t *testing.T) {
29192923Op :fsnotify .Write ,
29202924})
29212925
2922- err = api .RefreshContainers (ctx )
2923- require .NoError (t ,err )
2926+ require .Eventuallyf (t ,func ()bool {
2927+ err = api .RefreshContainers (ctx )
2928+ require .NoError (t ,err )
2929+
2930+ return len (fakeSAC .agents )== 0
2931+ },testutil .WaitShort ,testutil .IntervalFast ,"subagent should be deleted after config change" )
29242932
29252933req = httptest .NewRequest (http .MethodGet ,"/" ,nil ).WithContext (ctx )
29262934rec = httptest .NewRecorder ()