replace timers with chan signals

This commit is contained in:
inphi 2023-10-19 12:54:09 -04:00
parent 9b3bf9ac3a
commit 6f9a6504e4

View file

@ -158,12 +158,14 @@ func TestResubscribeWithErrorHandler(t *testing.T) {
func TestResubscribeWithCompletedSubscription(t *testing.T) { func TestResubscribeWithCompletedSubscription(t *testing.T) {
t.Parallel() 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) { sub := ResubscribeErr(100*time.Millisecond, func(ctx context.Context, lastErr error) (Subscription, error) {
return NewSubscription(func(unsubscribed <-chan struct{}) error { return NewSubscription(func(unsubscribed <-chan struct{}) error {
select { select {
case <-time.After(2 * time.Second): case <-quitProducer:
innerSubDone <- struct{}{} quitProducerAck <- struct{}{}
return nil return nil
case <-unsubscribed: case <-unsubscribed:
return nil return nil
@ -171,6 +173,8 @@ func TestResubscribeWithCompletedSubscription(t *testing.T) {
}), nil }), nil
}) })
<-innerSubDone // Ensure producer has started and exited before Unsubscribe
close(quitProducer)
<-quitProducerAck
sub.Unsubscribe() sub.Unsubscribe()
} }