test: ping has extra delay at the end#4862
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue where the ping function had an extra delay at the end of its execution. The change modifies the loop structure to avoid waiting for a final tick after all ping attempts have been sent.
Key changes:
- Restructured the ping sending loop to break before the final sleep/tick wait
- Changed from a traditional for loop to a manual counter decrement approach
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| defer log.HandlePanic() | ||
| defer wg.Done() | ||
| for i := uint16(0); i < p.attempts; i++ { | ||
|
|
There was a problem hiding this comment.
If p.attempts is 0, the loop will run indefinitely since i will underflow when decremented. Add a check to handle the case where p.attempts is 0, or ensure p.attempts is always greater than 0.
| if p.attempts == 0 { | |
| // No packets to send; avoid underflow in the decrementing loop. | |
| return | |
| } |
| defer wg.Done() | ||
| for i := uint16(0); i < p.attempts; i++ { | ||
|
|
||
| i := p.attempts |
There was a problem hiding this comment.
The variable i should retain the uint16 type annotation for clarity and to match the original type, e.g., i := uint16(p.attempts) or ensure type consistency with the original loop counter.
Fixes: #4861