Skip to content

Commit

Permalink
Cleaned up gross wait function
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Elliott <[email protected]>
  • Loading branch information
joe-elliott committed Nov 27, 2019
1 parent 5a3ce04 commit 8657535
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions internal/testutils/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ func GetAvailablePort(t *testing.T) uint16 {
func WaitForPort(t *testing.T, port uint16) error {
t.Helper()

duration := 100 * time.Millisecond
iterations := 50 // 50 * 100ms = 5 seconds
totalDuration := 5 * time.Second
wait := 100 * time.Millisecond
address := fmt.Sprintf("localhost:%d", port)
for i := 0; i < iterations; i++ {
for i := totalDuration; i > 0; i -= wait {
_, err := net.Dial("tcp", address)

if err == nil {
return nil
}
time.Sleep(duration)
time.Sleep(wait)
}
return fmt.Errorf("failed to wait for port %d", port)
}

0 comments on commit 8657535

Please sign in to comment.