Skip to content

Commit d873f10

Browse files
authored
Fix race in TestHandlerDispatchInternal (#1895)
1 parent 9b0615e commit d873f10

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

snow/networking/handler/handler_test.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ func TestHandlerDropsGossipDuringBootstrapping(t *testing.T) {
311311
func TestHandlerDispatchInternal(t *testing.T) {
312312
require := require.New(t)
313313

314-
calledNotify := make(chan struct{}, 1)
315314
ctx := snow.DefaultConsensusContextTest()
316315
msgFromVMChan := make(chan common.Message)
317316
vdrs := validators.NewSet()
@@ -352,8 +351,10 @@ func TestHandlerDispatchInternal(t *testing.T) {
352351
engine.ContextF = func() *snow.ConsensusContext {
353352
return ctx
354353
}
354+
355+
wg := &sync.WaitGroup{}
355356
engine.NotifyF = func(context.Context, common.Message) error {
356-
calledNotify <- struct{}{}
357+
wg.Done()
357358
return nil
358359
}
359360

@@ -373,14 +374,10 @@ func TestHandlerDispatchInternal(t *testing.T) {
373374
return nil
374375
}
375376

377+
wg.Add(1)
376378
handler.Start(context.Background(), false)
377379
msgFromVMChan <- 0
378-
379-
select {
380-
case <-time.After(20 * time.Millisecond):
381-
require.FailNow("should have called notify")
382-
case <-calledNotify:
383-
}
380+
wg.Wait()
384381
}
385382

386383
func TestHandlerSubnetConnector(t *testing.T) {

0 commit comments

Comments
 (0)