@cryptotaxi247 / kubo / commits / a9cb26c6b

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 <steven@stebalien.com>

Steven Allen committed Jun 15, 2018 at 20:06 UTC a9cb26c6b881fb3aa7431cb517479e0bae3f5de5
1 file changed +22 -7
namesys/republisher/repub_test.go
+22 -7
@@ -59,18 +59,33 @@ func TestRepublish(t *testing.T) {
59 publisher := nodes[3]
60 p := path.FromString("/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn") // does not need to be valid
61 rp := namesys.NewIpnsPublisher(publisher.Routing, publisher.Repo.Datastore())
62 - err := rp.PublishWithEOL(ctx, publisher.PrivateKey, p, time.Now().Add(time.Second))
63 - if err != nil {
64 - t.Fatal(err)
65 - }
66 -
62 name := "/ipns/" + publisher.Identity.Pretty()
68 - if err := verifyResolution(nodes, name, p); err != nil {
63 +
64 + // Retry in case the record expires before we can fetch it. This can
65 + // happen when running the test on a slow machine.
66 + var expiration time.Time
67 + timeout := time.Second
68 + for {
69 + expiration = time.Now().Add(time.Second)
70 + err := rp.PublishWithEOL(ctx, publisher.PrivateKey, p, expiration)
71 + if err != nil {
72 + t.Fatal(err)
73 + }
74 +
75 + err = verifyResolution(nodes, name, p)
76 + if err == nil {
77 + break
78 + }
79 +
80 + if time.Now().After(expiration) {
81 + timeout *= 2
82 + continue
83 + }
84 t.Fatal(err)
85 }
86
87 // Now wait a second, the records will be invalid and we should fail to resolve
73 - time.Sleep(time.Second)
88 + time.Sleep(timeout)
89 if err := verifyResolutionFails(nodes, name); err != nil {
90 t.Fatal(err)
91 }