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 <[email protected]>
  • Loading branch information
vyzo committed Jul 11, 2017
1 parent 6cd7c2c commit a477208
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 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,7 +113,8 @@ 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)
}

Expand All @@ -126,9 +127,10 @@ 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)
}

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 a477208

Please sign in to comment.