mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
replace timers with chan signals
This commit is contained in:
parent
9b3bf9ac3a
commit
6f9a6504e4
1 changed files with 8 additions and 4 deletions
|
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue