Skip to content

Commit

Permalink
crossdock: clean up wait()
Browse files Browse the repository at this point in the history
  • Loading branch information
HelloGrayson committed May 25, 2016
1 parent 3d8aea2 commit 873af32
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions crossdock/crossdock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,30 +115,26 @@ func TestCrossdock(t *testing.T) {
}

func wait(t *testing.T) {
attempts := 0
totalAttempts := 10
ctx := context.Background()
for {
if attempts > 9 {
t.Fatalf("could not talk to client in %d attempts", attempts)
}

attempts++

for attempts := 0; attempts < totalAttempts; attempts++ {
ctx, cancel := context.WithTimeout(ctx, time.Second)
defer cancel()

log.Println("HEAD", clientURL)

_, err := ctxhttp.Head(ctx, nil, clientURL)
if err == nil {
break
log.Println("Client is ready, beginning test...")
return
}

sleepFor := 100 * time.Millisecond
log.Println(err, "- sleeping for", sleepFor)
time.Sleep(sleepFor)
}
log.Println("Client is ready, beginning test...")
t.Fatalf("could not talk to client in %d attempts", totalAttempts)
}

func call(t *testing.T, args url.Values) {
Expand Down

0 comments on commit 873af32

Please sign in to comment.