@@ -178,24 +178,39 @@ func TestConnectAndWait(t *testing.T) {
178178 // TODO: this test cannot be executed with `t.Parallel()`, due to
179179 // relying on goroutine numbers to ensure correct behaviour
180180 t .Run ("connect goroutine exits after EOF" , func (t * testing.T ) {
181+ runtime .LockOSThread ()
182+ defer runtime .UnlockOSThread ()
181183 srv , err := NewPluginServer (nil )
182184 assert .NilError (t , err , "failed to setup server" )
183185
184186 defer srv .Close ()
185187
186188 t .Setenv (EnvKey , srv .Addr ().String ())
189+
190+ runtime .Gosched ()
187191 numGoroutines := runtime .NumGoroutine ()
188192
189193 ConnectAndWait (func () {})
190- assert .Equal (t , runtime .NumGoroutine (), numGoroutines + 1 )
194+
195+ runtime .Gosched ()
196+ poll .WaitOn (t , func (t poll.LogT ) poll.Result {
197+ // +1 goroutine for the poll.WaitOn
198+ // +1 goroutine for the connect goroutine
199+ if runtime .NumGoroutine () < numGoroutines + 1 + 1 {
200+ return poll .Continue ("waiting for connect goroutine to spawn" )
201+ }
202+ return poll .Success ()
203+ }, poll .WithDelay (1 * time .Millisecond ), poll .WithTimeout (500 * time .Millisecond ))
191204
192205 srv .Close ()
193206
207+ runtime .Gosched ()
194208 poll .WaitOn (t , func (t poll.LogT ) poll.Result {
209+ // +1 goroutine for the poll.WaitOn
195210 if runtime .NumGoroutine () > numGoroutines + 1 {
196211 return poll .Continue ("waiting for connect goroutine to exit" )
197212 }
198213 return poll .Success ()
199- }, poll .WithDelay (1 * time .Millisecond ), poll .WithTimeout (10 * time .Millisecond ))
214+ }, poll .WithDelay (1 * time .Millisecond ), poll .WithTimeout (500 * time .Millisecond ))
200215 })
201216}
0 commit comments