@@ -178,24 +178,39 @@ func TestConnectAndWait(t *testing.T) {
178
178
// TODO: this test cannot be executed with `t.Parallel()`, due to
179
179
// relying on goroutine numbers to ensure correct behaviour
180
180
t .Run ("connect goroutine exits after EOF" , func (t * testing.T ) {
181
+ runtime .LockOSThread ()
182
+ defer runtime .UnlockOSThread ()
181
183
srv , err := NewPluginServer (nil )
182
184
assert .NilError (t , err , "failed to setup server" )
183
185
184
186
defer srv .Close ()
185
187
186
188
t .Setenv (EnvKey , srv .Addr ().String ())
189
+
190
+ runtime .Gosched ()
187
191
numGoroutines := runtime .NumGoroutine ()
188
192
189
193
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 ))
191
204
192
205
srv .Close ()
193
206
207
+ runtime .Gosched ()
194
208
poll .WaitOn (t , func (t poll.LogT ) poll.Result {
209
+ // +1 goroutine for the poll.WaitOn
195
210
if runtime .NumGoroutine () > numGoroutines + 1 {
196
211
return poll .Continue ("waiting for connect goroutine to exit" )
197
212
}
198
213
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 ))
200
215
})
201
216
}
0 commit comments