From a9cb26c6b881fb3aa7431cb517479e0bae3f5de5 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 15 Jun 2018 20:06:44 -0700 Subject: [PATCH] make republisher test robust against timing issues retry publishing with a longer EOL if the first attempt fails due to a timeout. fixes #5099 License: MIT Signed-off-by: Steven Allen --- namesys/republisher/repub_test.go | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/namesys/republisher/repub_test.go b/namesys/republisher/repub_test.go index 9cc5a940e..8a76cbcc1 100644 --- a/namesys/republisher/repub_test.go +++ b/namesys/republisher/repub_test.go @@ -59,18 +59,33 @@ func TestRepublish(t *testing.T) { publisher := nodes[3] p := path.FromString("/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn") // does not need to be valid rp := namesys.NewIpnsPublisher(publisher.Routing, publisher.Repo.Datastore()) - err := rp.PublishWithEOL(ctx, publisher.PrivateKey, p, time.Now().Add(time.Second)) - if err != nil { - t.Fatal(err) - } - name := "/ipns/" + publisher.Identity.Pretty() - if err := verifyResolution(nodes, name, p); err != nil { + + // Retry in case the record expires before we can fetch it. This can + // happen when running the test on a slow machine. + var expiration time.Time + timeout := time.Second + for { + expiration = time.Now().Add(time.Second) + err := rp.PublishWithEOL(ctx, publisher.PrivateKey, p, expiration) + if err != nil { + t.Fatal(err) + } + + err = verifyResolution(nodes, name, p) + if err == nil { + break + } + + if time.Now().After(expiration) { + timeout *= 2 + continue + } t.Fatal(err) } // Now wait a second, the records will be invalid and we should fail to resolve - time.Sleep(time.Second) + time.Sleep(timeout) if err := verifyResolutionFails(nodes, name); err != nil { t.Fatal(err) }