mirror of
https://github.com/libp2p/go-libp2p-peerstore.git
synced 2025-03-23 13:00:08 +08:00
add test for multiple subscriptions
This commit is contained in:
parent
dd7efed6ee
commit
76e427fca8
@ -54,6 +54,10 @@ func TestAddrStream(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// start a second stream
|
||||
ctx2, cancel2 := context.WithCancel(context.Background())
|
||||
addrch2 := ps.AddrStream(ctx2, pid)
|
||||
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer close(done)
|
||||
@ -83,9 +87,17 @@ func TestAddrStream(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// now cancel it, and add a few more addresses it doesnt hang afterwards
|
||||
// now cancel it
|
||||
cancel()
|
||||
|
||||
// now check the *second* subscription. We should see 80 addresses.
|
||||
for i := 0; i < 80; i++ {
|
||||
<-addrch2
|
||||
}
|
||||
|
||||
cancel2()
|
||||
|
||||
// and add a few more addresses it doesnt hang afterwards
|
||||
for _, a := range addrs[80:] {
|
||||
ps.AddAddr(pid, a, time.Hour)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user