mirror of
https://github.com/logos-messaging/go-libp2p-pubsub.git
synced 2026-01-08 15:53:07 +00:00
make star topology tests more reliable
probabilities are such that they occasionally fail
This commit is contained in:
parent
1a3695988b
commit
caffc3bf2c
@ -942,6 +942,18 @@ func TestGossipsubTreeTopology(t *testing.T) {
|
|||||||
// this tests overlay bootstrapping through px in Gossipsub v1.1
|
// this tests overlay bootstrapping through px in Gossipsub v1.1
|
||||||
// we start with a star topology and rely on px through prune to build the mesh
|
// we start with a star topology and rely on px through prune to build the mesh
|
||||||
func TestGossipsubStarTopology(t *testing.T) {
|
func TestGossipsubStarTopology(t *testing.T) {
|
||||||
|
originalGossipSubD := GossipSubD
|
||||||
|
GossipSubD = 4
|
||||||
|
originalGossipSubDhi := GossipSubDhi
|
||||||
|
GossipSubDhi = GossipSubD + 1
|
||||||
|
originalGossipSubDlo := GossipSubDlo
|
||||||
|
GossipSubDlo = GossipSubD - 1
|
||||||
|
defer func() {
|
||||||
|
GossipSubD = originalGossipSubD
|
||||||
|
GossipSubDhi = originalGossipSubDhi
|
||||||
|
GossipSubDlo = originalGossipSubDlo
|
||||||
|
}()
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
@ -965,6 +977,8 @@ func TestGossipsubStarTopology(t *testing.T) {
|
|||||||
connect(t, hosts[0], hosts[i])
|
connect(t, hosts[0], hosts[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
|
||||||
// build the mesh
|
// build the mesh
|
||||||
var subs []*Subscription
|
var subs []*Subscription
|
||||||
for _, ps := range psubs {
|
for _, ps := range psubs {
|
||||||
@ -979,9 +993,9 @@ func TestGossipsubStarTopology(t *testing.T) {
|
|||||||
time.Sleep(10 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
|
|
||||||
// check that all peers have > 1 connection
|
// check that all peers have > 1 connection
|
||||||
for _, h := range hosts {
|
for i, h := range hosts {
|
||||||
if len(h.Network().Conns()) == 1 {
|
if len(h.Network().Conns()) == 1 {
|
||||||
t.Error("peer has ony a single connection")
|
t.Errorf("peer %d has ony a single connection", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1000,6 +1014,18 @@ func TestGossipsubStarTopology(t *testing.T) {
|
|||||||
// exchanged in signed peer records.
|
// exchanged in signed peer records.
|
||||||
// we start with a star topology and rely on px through prune to build the mesh
|
// we start with a star topology and rely on px through prune to build the mesh
|
||||||
func TestGossipsubStarTopologyWithSignedPeerRecords(t *testing.T) {
|
func TestGossipsubStarTopologyWithSignedPeerRecords(t *testing.T) {
|
||||||
|
originalGossipSubD := GossipSubD
|
||||||
|
GossipSubD = 4
|
||||||
|
originalGossipSubDhi := GossipSubDhi
|
||||||
|
GossipSubDhi = GossipSubD + 1
|
||||||
|
originalGossipSubDlo := GossipSubDlo
|
||||||
|
GossipSubDlo = GossipSubD - 1
|
||||||
|
defer func() {
|
||||||
|
GossipSubD = originalGossipSubD
|
||||||
|
GossipSubDhi = originalGossipSubDhi
|
||||||
|
GossipSubDlo = originalGossipSubDlo
|
||||||
|
}()
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
@ -1035,6 +1061,8 @@ func TestGossipsubStarTopologyWithSignedPeerRecords(t *testing.T) {
|
|||||||
connect(t, hosts[0], hosts[i])
|
connect(t, hosts[0], hosts[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
|
||||||
// build the mesh
|
// build the mesh
|
||||||
var subs []*Subscription
|
var subs []*Subscription
|
||||||
for _, ps := range psubs {
|
for _, ps := range psubs {
|
||||||
@ -1049,9 +1077,9 @@ func TestGossipsubStarTopologyWithSignedPeerRecords(t *testing.T) {
|
|||||||
time.Sleep(10 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
|
|
||||||
// check that all peers have > 1 connection
|
// check that all peers have > 1 connection
|
||||||
for _, h := range hosts {
|
for i, h := range hosts {
|
||||||
if len(h.Network().Conns()) == 1 {
|
if len(h.Network().Conns()) == 1 {
|
||||||
t.Error("peer has ony a single connection")
|
t.Errorf("peer %d has ony a single connection", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user