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)
This commit is contained in:
Roman Khimov 2021-07-08 11:03:30 +03:00
parent bd400dfe20
commit 9cc4f42a71

View file

@ -27,12 +27,13 @@ func newFakeTransp(s *Server) Transporter {
} }
func (ft *fakeTransp) Dial(addr string, timeout time.Duration) error { 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 ft.dialCh <- addr
if atomic.LoadInt32(&ft.retFalse) > 0 { return ret
return errors.New("smth bad happened")
}
return nil
} }
func (ft *fakeTransp) Accept() { func (ft *fakeTransp) Accept() {
if ft.started.Load() { if ft.started.Load() {