Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd: alpha test peers tests self #3052

Merged
merged 9 commits into from
May 8, 2024
13 changes: 11 additions & 2 deletions cmd/testpeers.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,30 +570,39 @@
return testRes
}

func dialTCPIP(ctx context.Context, address string) error {
func dialLibp2pTCPIP(ctx context.Context, address string) error {
d := net.Dialer{Timeout: time.Second}
conn, err := d.DialContext(ctx, "tcp", address)
if err != nil {
return errors.Wrap(err, "net dial")
}
buf := new(strings.Builder)
KaloyanTanev marked this conversation as resolved.
Show resolved Hide resolved
_, err = io.Copy(buf, conn)
if err != nil {
return errors.Wrap(err, "io copy")

Check warning on line 582 in cmd/testpeers.go

View check run for this annotation

Codecov / codecov/patch

cmd/testpeers.go#L573-L582

Added lines #L573 - L582 were not covered by tests
}
if !strings.Contains(buf.String(), "/multistream/1.0.0") {
return errors.New("multistream not found", z.Any("found", buf.String()), z.Any("address", address))
}

err = conn.Close()
if err != nil {
return errors.Wrap(err, "close conn")

Check warning on line 590 in cmd/testpeers.go

View check run for this annotation

Codecov / codecov/patch

cmd/testpeers.go#L585-L590

Added lines #L585 - L590 were not covered by tests
}

return nil
}

func libp2pTCPPortOpenTest(ctx context.Context, cfg *testPeersConfig) testResult {
testRes := testResult{Name: "Libp2pTCPPortOpen"}

Check warning on line 598 in cmd/testpeers.go

View check run for this annotation

Codecov / codecov/patch

cmd/testpeers.go#L592-L598

Added lines #L592 - L598 were not covered by tests
group, _ := errgroup.WithContext(ctx)

for _, addr := range cfg.P2P.TCPAddrs {
KaloyanTanev marked this conversation as resolved.
Show resolved Hide resolved
addrVal := addr
group.Go(func() error { return dialTCPIP(ctx, addrVal) })
group.Go(func() error { return dialLibp2pTCPIP(ctx, addrVal) })

Check warning on line 603 in cmd/testpeers.go

View check run for this annotation

Codecov / codecov/patch

cmd/testpeers.go#L600-L603

Added lines #L600 - L603 were not covered by tests
}

Check warning on line 605 in cmd/testpeers.go

View check run for this annotation

Codecov / codecov/patch

cmd/testpeers.go#L605

Added line #L605 was not covered by tests
err := group.Wait()
if err != nil {
testRes.Verdict = testVerdictFail
Expand All @@ -602,7 +611,7 @@
return testRes
}

testRes.Verdict = testVerdictOk

Check warning on line 615 in cmd/testpeers.go

View check run for this annotation

Codecov / codecov/patch

cmd/testpeers.go#L614-L615

Added lines #L614 - L615 were not covered by tests
return testRes
}
Loading