Skip to content

Commit

Permalink
Merge pull request #5125 from ipfs/fix/5099
Browse files Browse the repository at this point in the history
make republisher test robust against timing issues
  • Loading branch information
whyrusleeping authored Jun 17, 2018
2 parents b516aa1 + a9cb26c commit ebb040a
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions namesys/republisher/repub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit ebb040a

Please sign in to comment.