mirror of
https://github.com/libp2p/go-eventbus.git
synced 2025-03-13 10:20:10 +08:00
fix panic in TestSubFailFully
This commit is contained in:
parent
eef4f37eb1
commit
8f33a3e22f
@ -455,11 +455,6 @@ func TestCloseBlocking(t *testing.T) {
|
|||||||
sub.Close() // cancel sub
|
sub.Close() // cancel sub
|
||||||
}
|
}
|
||||||
|
|
||||||
func panicOnTimeout(d time.Duration) {
|
|
||||||
<-time.After(d)
|
|
||||||
panic("timeout reached")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSubFailFully(t *testing.T) {
|
func TestSubFailFully(t *testing.T) {
|
||||||
bus := NewBus()
|
bus := NewBus()
|
||||||
em, err := bus.Emitter(new(EventB))
|
em, err := bus.Emitter(new(EventB))
|
||||||
@ -472,9 +467,17 @@ func TestSubFailFully(t *testing.T) {
|
|||||||
t.Fatal(err)
|
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) {
|
func testMany(t testing.TB, subs, emits, msgs int, stateful bool) {
|
||||||
|
Loading…
Reference in New Issue
Block a user