From 212cd199574a6288c594842e33b0f2e50866cb89 Mon Sep 17 00:00:00 2001 From: sukun Date: Tue, 23 May 2023 20:10:37 +0530 Subject: [PATCH] fix flaky test --- p2p/net/swarm/dial_worker_test.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/p2p/net/swarm/dial_worker_test.go b/p2p/net/swarm/dial_worker_test.go index 94e5fc299a..f64f6feea3 100644 --- a/p2p/net/swarm/dial_worker_test.go +++ b/p2p/net/swarm/dial_worker_test.go @@ -116,6 +116,7 @@ func makeUpgrader(t *testing.T, n *Swarm) transport.Upgrader { // channel ch will close an accepted connection func makeTCPListener(t *testing.T, a ma.Multiaddr, recvCh chan struct{}) (list manet.Listener, ch chan struct{}) { t.Helper() + log.Errorf("listening on %s", a) list, err := manet.Listen(a) if err != nil { t.Fatal(err) @@ -523,7 +524,7 @@ func (s schedulingTestCase) Generate(rand *mrand.Rand, size int) reflect.Value { delays := make(map[time.Duration]struct{}) for i := 0; i < size; i++ { input[i] = timedDial{ - addr: ma.StringCast(fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", i+10000)), + addr: ma.StringCast(fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", i+10550)), delay: time.Duration(mrand.Intn(100)) * 10 * time.Millisecond, // max 1 second success: false, failAfter: time.Duration(mrand.Intn(100)) * 10 * time.Millisecond, // max 1 second @@ -596,7 +597,6 @@ func checkDialWorkerLoopScheduling(t *testing.T, s1, s2 *Swarm, tc schedulingTes f := func() { err := l.Close() if err != nil { - log.Error(err) t.Error(err) } } @@ -668,7 +668,9 @@ loop: if r.conn == nil { return errors.New("expected connection to succeed") } - case <-time.After(1 * time.Second): + // High timeout here is okay. We will exit whenever the other branch + // is triggered + case <-time.After(10 * time.Second): return errors.New("expected to receive a response") } connected = true @@ -679,7 +681,9 @@ loop: case <-recvCh: case <-resch: return errors.New("didn't expect a response") - case <-time.After(100 * time.Millisecond): + // High timeout here is okay. We will exit whenever the other branch + // is triggered + case <-time.After(10 * time.Second): return errors.New("didn't receive a dial attempt notification") } failDials[a] = dialState{ @@ -899,6 +903,9 @@ func TestDialWorkerLoopSchedulingProperty(t *testing.T) { // setup the ranker to trigger dials according to the test case s1.dialRanker = makeRanker(tc.input) err := checkDialWorkerLoopScheduling(t, s1, s2, tc) + if err != nil { + log.Error(err) + } return err == nil }