Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make republisher test robust against timing issues #5125

Merged
merged 1 commit into from
Jun 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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