mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
28e61fa40c
* Only build with cgosymbolizer when explicitly desired. This fixes go builds for mac and others * Try to dial external IP set and display a warning message is not reachable * fix dialTimeout adding the port * add connectivity check for UDP as well * add connectivy verification for both UDP and TCP and move function in p2p/utils.go * return if Resolving UDP fails * move constant in utils * add missing time dependencies * leverage dial for both TCP/UDP (even thoguh UDP is not supported & add a unit tests for `verifyConnectivity` * handle err from conn.Close() * add utils_test go p2p gazelle * Update beacon-chain/p2p/utils.go Co-authored-by: Ivan Martinez <ivanthegreatdev@gmail.com> * Update beacon-chain/p2p/utils.go Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/p2p/utils.go Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> * do not defer closing the connection * leverage util helper testutil.AssertLogsContain and testutil.AssertLogsDoNotContain * remove old code Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: Ivan Martinez <ivanthegreatdev@gmail.com>
37 lines
1.0 KiB
Go
37 lines
1.0 KiB
Go
package p2p
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
)
|
|
|
|
// Test `verifyConnectivity` function by trying to connect to google.com (successfully)
|
|
// and then by connecting to an unreachable IP and ensuring that a log is emitted
|
|
func TestVerifyConnectivity(t *testing.T) {
|
|
hook := logTest.NewGlobal()
|
|
cases := []struct {
|
|
address string
|
|
port uint
|
|
expectedConnectivity bool
|
|
name string
|
|
}{
|
|
{"142.250.68.46", 80, true, "Dialing a reachable IP: 142.250.68.46:80"}, // google.com
|
|
{"123.123.123.123", 19000, false, "Dialing an unreachable IP: 123.123.123.123:19000"},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(fmt.Sprintf(tc.name),
|
|
func(t *testing.T) {
|
|
verifyConnectivity(tc.address, tc.port, "tcp")
|
|
logMessage := "IP address is not accessible"
|
|
if tc.expectedConnectivity {
|
|
testutil.AssertLogsDoNotContain(t, hook, logMessage)
|
|
} else {
|
|
testutil.AssertLogsContain(t, hook, logMessage)
|
|
}
|
|
})
|
|
}
|
|
}
|