From 8f33a3e22ffa69e4772642dfdb9fe7c814c76811 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Wed, 17 Aug 2022 11:56:53 +0300 Subject: [PATCH] fix panic in TestSubFailFully --- basic_test.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/basic_test.go b/basic_test.go index 172f3f2..95faebe 100644 --- a/basic_test.go +++ b/basic_test.go @@ -455,11 +455,6 @@ func TestCloseBlocking(t *testing.T) { sub.Close() // cancel sub } -func panicOnTimeout(d time.Duration) { - <-time.After(d) - panic("timeout reached") -} - func TestSubFailFully(t *testing.T) { bus := NewBus() em, err := bus.Emitter(new(EventB)) @@ -472,9 +467,17 @@ func TestSubFailFully(t *testing.T) { t.Fatal(err) } - go panicOnTimeout(5 * time.Second) + done := make(chan struct{}) + go func() { + defer close(done) + em.Emit(EventB(159)) // will hang if sub doesn't fail properly + }() - em.Emit(EventB(159)) // will hang if sub doesn't fail properly + select { + case <-done: + case <-time.After(5 * time.Second): + t.Fatal("timeout") + } } func testMany(t testing.TB, subs, emits, msgs int, stateful bool) {