mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00

* [NOD-1223] Move all network stuff into a new network package. * [NOD-1223] Delete the unused package testutil. * [NOD-1223] Move infrastructure stuff into a new instrastructure package. * [NOD-1223] Move domain stuff into a new domain package.
71 lines
1.6 KiB
Go
71 lines
1.6 KiB
Go
package integration
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func connect(t *testing.T, incoming, outgoing *appHarness) {
|
|
err := outgoing.rpcClient.ConnectNode(incoming.p2pAddress)
|
|
if err != nil {
|
|
t.Fatalf("Error connecting the nodes")
|
|
}
|
|
|
|
onConnectedChan := make(chan struct{})
|
|
abortConnectionChan := make(chan struct{})
|
|
defer close(abortConnectionChan)
|
|
|
|
spawn("integration.connect-Wait for connection", func() {
|
|
ticker := time.NewTicker(10 * time.Millisecond)
|
|
defer ticker.Stop()
|
|
|
|
for range ticker.C {
|
|
if isConnected(t, incoming, outgoing) {
|
|
close(onConnectedChan)
|
|
return
|
|
}
|
|
|
|
select {
|
|
case <-abortConnectionChan:
|
|
return
|
|
default:
|
|
}
|
|
}
|
|
})
|
|
|
|
select {
|
|
case <-onConnectedChan:
|
|
case <-time.After(defaultTimeout):
|
|
t.Fatalf("Timed out waiting for the apps to connect")
|
|
}
|
|
}
|
|
func isConnected(t *testing.T, appHarness1, appHarness2 *appHarness) bool {
|
|
connectedPeerInfo1, err := appHarness1.rpcClient.GetConnectedPeerInfo()
|
|
if err != nil {
|
|
t.Fatalf("Error getting connected peer info for app1: %+v", err)
|
|
}
|
|
connectedPeerInfo2, err := appHarness2.rpcClient.GetConnectedPeerInfo()
|
|
if err != nil {
|
|
t.Fatalf("Error getting connected peer info for app2: %+v", err)
|
|
}
|
|
|
|
var incomingConnected, outgoingConnected bool
|
|
app1ID, app2ID := appHarness1.app.P2PNodeID().String(), appHarness2.app.P2PNodeID().String()
|
|
|
|
for _, connectedPeer := range connectedPeerInfo1 {
|
|
if connectedPeer.ID == app2ID {
|
|
incomingConnected = true
|
|
break
|
|
}
|
|
}
|
|
|
|
for _, connectedPeer := range connectedPeerInfo2 {
|
|
if connectedPeer.ID == app1ID {
|
|
outgoingConnected = true
|
|
break
|
|
}
|
|
}
|
|
|
|
return incomingConnected && outgoingConnected
|
|
}
|