Skip to content

Commit

Permalink
namesys/pubsub_test: smaller test
Browse files Browse the repository at this point in the history
make it work with seemingly low fdlimits in travis/macosx.
also, more informative test failures.

License: MIT
Signed-off-by: vyzo <vyzo@hackzen.org>
  • Loading branch information
vyzo committed Jul 11, 2017
1 parent 6cd7c2c commit 7d7d693
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions namesys/pubsub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestPubsubPublishResolve(t *testing.T) {

name := "/ipns/" + pubhost.ID().Pretty()

reshosts := newNetHosts(ctx, t, 20)
reshosts := newNetHosts(ctx, t, 5)
resmrs := newMockRoutingForHosts(ms, ks, reshosts)
res := make([]Resolver, len(reshosts))
for i := 0; i < len(res); i++ {
Expand All @@ -113,22 +113,24 @@ func TestPubsubPublishResolve(t *testing.T) {

time.Sleep(time.Millisecond * 100)
for i := 0; i < len(res); i++ {
checkResolveNotFound(ctx, t, res[i], name)
checkResolveNotFound(ctx, t, i, res[i], name)
// delay to avoid connection storms
time.Sleep(time.Millisecond * 100)
}

// let the bootstrap finish
time.Sleep(time.Second * 3)
time.Sleep(time.Second * 1)

val := path.Path("/ipfs/QmP1DfoUjiWH2ZBo1PBH6FupdBucbDepx3HpWmEY6JMUpY")
err := pub.Publish(ctx, privk, val)
if err != nil {
t.Fatal(err)
}

// let the flood propagate
time.Sleep(time.Second * 3)
for i := 0; i < len(res); i++ {
checkResolve(ctx, t, res[i], name, val)
checkResolve(ctx, t, i, res[i], name, val)
}

val = path.Path("/ipfs/QmP1wMAqk6aZYRZirbaAwmrNeqFRgQrwBt3orUtvSa1UYD")
Expand All @@ -137,25 +139,26 @@ func TestPubsubPublishResolve(t *testing.T) {
t.Fatal(err)
}

// let the flood propagate
time.Sleep(time.Second * 3)
for i := 0; i < len(res); i++ {
checkResolve(ctx, t, res[i], name, val)
checkResolve(ctx, t, i, res[i], name, val)
}
}

func checkResolveNotFound(ctx context.Context, t *testing.T, resolver Resolver, name string) {
func checkResolveNotFound(ctx context.Context, t *testing.T, i int, resolver Resolver, name string) {
_, err := resolver.Resolve(ctx, name)
if err != ds.ErrNotFound {
t.Fatalf("unexpected value: %#v", err)
t.Fatalf("[resolver %d] unexpected error: %s", i, err.Error())
}
}

func checkResolve(ctx context.Context, t *testing.T, resolver Resolver, name string, val path.Path) {
func checkResolve(ctx context.Context, t *testing.T, i int, resolver Resolver, name string, val path.Path) {
xval, err := resolver.Resolve(ctx, name)
if err != nil {
t.Fatal(err)
t.Fatalf("[resolver %d] resolve failed: %s", i, err.Error())
}
if xval != val {
t.Fatalf("resolver resolves to unexpected value %s %s", val, xval)
t.Fatalf("[resolver %d] unexpected value: %s %s", i, val, xval)
}
}

0 comments on commit 7d7d693

Please sign in to comment.