From 6f9a6504e44b1ce1b969daa850fb7bb1d4347959 Mon Sep 17 00:00:00 2001 From: inphi Date: Thu, 19 Oct 2023 12:54:09 -0400 Subject: [PATCH] replace timers with chan signals --- event/subscription_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/event/subscription_test.go b/event/subscription_test.go index 06b4a4941b..743d0bf67d 100644 --- a/event/subscription_test.go +++ b/event/subscription_test.go @@ -158,12 +158,14 @@ func TestResubscribeWithErrorHandler(t *testing.T) { func TestResubscribeWithCompletedSubscription(t *testing.T) { t.Parallel() - innerSubDone := make(chan struct{}, 1) + quitProducerAck := make(chan struct{}) + quitProducer := make(chan struct{}) + sub := ResubscribeErr(100*time.Millisecond, func(ctx context.Context, lastErr error) (Subscription, error) { return NewSubscription(func(unsubscribed <-chan struct{}) error { select { - case <-time.After(2 * time.Second): - innerSubDone <- struct{}{} + case <-quitProducer: + quitProducerAck <- struct{}{} return nil case <-unsubscribed: return nil @@ -171,6 +173,8 @@ func TestResubscribeWithCompletedSubscription(t *testing.T) { }), nil }) - <-innerSubDone + // Ensure producer has started and exited before Unsubscribe + close(quitProducer) + <-quitProducerAck sub.Unsubscribe() }