fix identify tests

This commit is contained in:
vyzo 2019-04-09 13:20:38 +03:00
parent 9b8192b7d2
commit f4af8d493d
2 changed files with 12 additions and 4 deletions

View File

@ -26,8 +26,8 @@ func subtestIDService(t *testing.T) {
h1p := h1.ID()
h2p := h2.ID()
ids1 := identify.NewIDService(h1)
ids2 := identify.NewIDService(h2)
ids1 := identify.NewIDService(ctx, h1)
ids2 := identify.NewIDService(ctx, h2)
testKnowsAddrs(t, h1, h2p, []ma.Multiaddr{}) // nothing
testKnowsAddrs(t, h2, h1p, []ma.Multiaddr{}) // nothing

View File

@ -1,6 +1,7 @@
package identify
import (
"context"
"sync"
"testing"
"time"
@ -52,7 +53,9 @@ func TestObsAddrSet(t *testing.T) {
b4 := m("/ip4/1.2.3.9/tcp/1237")
b5 := m("/ip4/1.2.3.10/tcp/1237")
oas := &ObservedAddrSet{}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
oas := NewObservedAddrSet(ctx)
if !addrsMarch(oas.Addrs(), nil) {
t.Error("addrs should be empty")
@ -63,6 +66,7 @@ func TestObsAddrSet(t *testing.T) {
dummyDirection := net.DirOutbound
oas.Add(observed, dummyLocal, observer, dummyDirection)
time.Sleep(1 * time.Millisecond) // let the worker run
}
add(oas, a1, a4)
@ -131,13 +135,17 @@ func TestAddAddrsProfile(b *testing.T) {
}
return m
}
oas := &ObservedAddrSet{}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
oas := NewObservedAddrSet(ctx)
add := func(oas *ObservedAddrSet, observed, observer ma.Multiaddr) {
dummyLocal := m("/ip4/127.0.0.1/tcp/10086")
dummyDirection := net.DirOutbound
oas.Add(observed, dummyLocal, observer, dummyDirection)
time.Sleep(1 * time.Millisecond) // let the worker run
}
a1 := m("/ip4/1.2.3.4/tcp/1231")