Skip to content

Commit

Permalink
relaysvc: flaky TestReachabilityChangeEvent (#2215)
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunrt committed Mar 24, 2023
1 parent b23d8b5 commit 6cab5e8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
4 changes: 2 additions & 2 deletions p2p/host/relaysvc/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ func TestReachabilityChangeEvent(t *testing.T) {
require.Eventually(
t,
func() bool { rmgr.mutex.Lock(); defer rmgr.mutex.Unlock(); relay = rmgr.relay; return relay != nil },
1*time.Second,
3*time.Second,
100*time.Millisecond,
"relay should be set on public event")
emitter.Emit(evt)
require.Never(t,
func() bool { rmgr.mutex.Lock(); defer rmgr.mutex.Unlock(); return relay != rmgr.relay },
1*time.Second,
3*time.Second,
100*time.Millisecond,
"relay should not be updated on receiving the same event")
}
6 changes: 1 addition & 5 deletions p2p/protocol/circuitv2/relay/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ type Relay struct {
constraints *constraints
scope network.ResourceScopeSpan
notifiee network.Notifiee
wg sync.WaitGroup

mx sync.Mutex
rsvp map[peer.ID]time.Time
Expand Down Expand Up @@ -106,7 +105,6 @@ func New(h host.Host, opts ...Option) (*Relay, error) {
if r.metricsTracer != nil {
r.metricsTracer.RelayStatus(true)
}
r.wg.Add(1)
go r.background()

return r, nil
Expand All @@ -122,10 +120,10 @@ func (r *Relay) Close() error {
r.host.Network().StopNotify(r.notifiee)
r.scope.Done()
r.cancel()
r.gc()
if r.metricsTracer != nil {
r.metricsTracer.RelayStatus(false)
}
r.wg.Wait()
return nil
}
r.mx.Unlock()
Expand Down Expand Up @@ -636,8 +634,6 @@ func (r *Relay) background() {
case <-ticker.C:
r.gc()
case <-r.ctx.Done():
r.gc()
r.wg.Done()
return
}
}
Expand Down

0 comments on commit 6cab5e8

Please sign in to comment.