Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
envestcc committed Aug 2, 2024
1 parent a45755e commit bbeabb4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,4 @@ replace github.com/ethereum/go-ethereum => github.com/iotexproject/go-ethereum v

replace golang.org/x/xerrors => golang.org/x/xerrors v0.0.0-20190212162355-a5947ffaace3

replace github.com/iotexproject/go-p2p => github.com/envestcc/go-p2p v0.0.0-20240802000837-c460de3bd6f5
replace github.com/iotexproject/go-p2p => github.com/envestcc/go-p2p v0.0.0-20240802031816-06161be30f97
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM=
github.com/envestcc/go-p2p v0.0.0-20240802000837-c460de3bd6f5 h1:buB6N/N3p+zb6x3oP3DxpncO6W+mjCmkbcmEhLxhSzU=
github.com/envestcc/go-p2p v0.0.0-20240802000837-c460de3bd6f5/go.mod h1:NpNWTfL9yzABgfwfMfIpicuDm/YkHHQ2aP6XuyMxgBM=
github.com/envestcc/go-p2p v0.0.0-20240802031816-06161be30f97 h1:Pok8zzLh1hnJVRq4/fjoIKNhEZMuUlH8Kev3quoKklU=
github.com/envestcc/go-p2p v0.0.0-20240802031816-06161be30f97/go.mod h1:NpNWTfL9yzABgfwfMfIpicuDm/YkHHQ2aP6XuyMxgBM=
github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down
23 changes: 16 additions & 7 deletions p2p/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestBroadcast(t *testing.T) {
ReconnectInterval: 150 * time.Second,
MaxMessageSize: p2p.DefaultConfig.MaxMessageSize,
}, 1, hash.ZeroHash256, b, u, JoinSubnet(_blockNetwork))
agent.Start(ctx)
r.NoError(agent.Start(ctx))
agents = append(agents, agent)
}

Expand Down Expand Up @@ -273,26 +273,35 @@ func TestUnicast(t *testing.T) {
}
src = peer.ID.Pretty()
}

bootnode, err := p2p.NewHost(context.Background(), p2p.DHTProtocolID(2), p2p.Port(testutil.RandomPort()), p2p.SecureIO(), p2p.MasterKey("bootnode"))
chainID := uint32(1)
bootnodePort := testutil.RandomPort()
bootnode, err := p2p.NewHost(context.Background(), p2p.DHTProtocolID(chainID), p2p.Port(bootnodePort), p2p.SecureIO(), p2p.MasterKey("bootnode"))
r.NoError(err)
addrs := bootnode.Addresses()
for i := 0; i < n; i++ {
port := bootnodePort + i + 1
agent := NewAgent(Config{
Host: "127.0.0.1",
Port: testutil.RandomPort(),
Port: port,
BootstrapNodes: []string{addrs[0].String()},
ReconnectInterval: 150 * time.Second,
MasterKey: strconv.Itoa(i),
}, 2, hash.ZeroHash256, b, u, JoinSubnet(_blockNetwork))
MaxMessageSize: p2p.DefaultConfig.MaxMessageSize,
}, chainID, hash.ZeroHash256, b, u, JoinSubnet(_blockNetwork))
r.NoError(agent.Start(ctx))
agents = append(agents, agent)
}

for i := 0; i < n; i++ {
neighbors, err := agents[i].Subnet(_blockNetwork).ConnectedPeers()
var (
neighbors []peer.AddrInfo
err error
)
err = testutil.WaitUntil(100*time.Millisecond, 2*time.Second, func() (bool, error) {
neighbors, err = agents[i].Subnet(_blockNetwork).ConnectedPeers()
return len(neighbors) >= n/3, err
})
r.NoError(err)
r.True(len(neighbors) >= n/3)
for _, neighbor := range neighbors {
r.NoError(agents[i].Subnet(_blockNetwork).UnicastOutbound(ctx, neighbor, &testingpb.TestPayload{
MsgBody: []byte{uint8(i)},
Expand Down

0 comments on commit bbeabb4

Please sign in to comment.