Skip to content

Commit

Permalink
Refactor log and move function to test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
KaloyanTanev committed Jul 22, 2024
1 parent 612aa6d commit 8bf346d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
11 changes: 11 additions & 0 deletions cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,14 @@ func blockAndWait(ctx context.Context, awaitTime time.Duration) {
log.Info(ctx, "Forcefully stopped")
}
}

func sleepWithContext(ctx context.Context, d time.Duration) {
timer := time.NewTimer(d)
select {
case <-ctx.Done():
if !timer.Stop() {
<-timer.C
}

Check warning on line 333 in cmd/test.go

View check run for this annotation

Codecov / codecov/patch

cmd/test.go#L332-L333

Added lines #L332 - L333 were not covered by tests
case <-timer.C:
}
}
11 changes: 0 additions & 11 deletions cmd/testpeers.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,6 @@ func pingPeerContinuously(ctx context.Context, tcpNode host.Host, peer p2p.Peer,
}
}

func sleepWithContext(ctx context.Context, d time.Duration) {
timer := time.NewTimer(d)
select {
case <-ctx.Done():
if !timer.Stop() {
<-timer.C
}
case <-timer.C:
}
}

func runTestPeers(ctx context.Context, w io.Writer, conf testPeersConfig) error {
peerTestCases := supportedPeerTestCases()
queuedTestsPeer := filterTests(maps.Keys(peerTestCases), conf.testConfig)
Expand Down
3 changes: 2 additions & 1 deletion cmd/testvalidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func pingValidatorContinuously(ctx context.Context, address string, resCh chan<-
}

func validatorPingLoadTest(ctx context.Context, conf *testValidatorConfig) testResult {
log.Info(ctx, "Running validator load tests...",
log.Info(ctx, "Running ping load tests...",
z.Any("duration", conf.LoadTestDuration),
z.Any("target", conf.APIAddress),
)
Expand All @@ -256,6 +256,7 @@ func validatorPingLoadTest(ctx context.Context, conf *testValidatorConfig) testR
}
wg.Wait()
close(testResCh)
log.Info(ctx, "Ping load tests finished", z.Any("target", conf.APIAddress))

highestRTT := time.Duration(0)
for rtt := range testResCh {
Expand Down

0 comments on commit 8bf346d

Please sign in to comment.