From 9cc4f42a7157e8ea9e6e8904ff0db7f796f0cbc0 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 8 Jul 2021 11:03:30 +0300 Subject: [PATCH] network: fix discoverer test Asynchronous tryAddress() routines may get dial result AFTER the switch to another test, so we need to ensure that they'll get the result intended for this particular call. Fixes: 2021-07-07T20:25:40.1624521Z === RUN TestDefaultDiscoverer 2021-07-07T20:25:40.1625316Z discovery_test.go:159: timeout expecting for transport dial; i: 2, j: 1 2021-07-07T20:25:40.1626319Z --- FAIL: TestDefaultDiscoverer (1.19s) --- pkg/network/discovery_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/network/discovery_test.go b/pkg/network/discovery_test.go index f8690764e..79d00b78d 100644 --- a/pkg/network/discovery_test.go +++ b/pkg/network/discovery_test.go @@ -27,12 +27,13 @@ func newFakeTransp(s *Server) Transporter { } func (ft *fakeTransp) Dial(addr string, timeout time.Duration) error { + var ret error + if atomic.LoadInt32(&ft.retFalse) > 0 { + ret = errors.New("smth bad happened") + } ft.dialCh <- addr - if atomic.LoadInt32(&ft.retFalse) > 0 { - return errors.New("smth bad happened") - } - return nil + return ret } func (ft *fakeTransp) Accept() { if ft.started.Load() {