Skip to content

Commit

Permalink
cert: make roundtrip more robust
Browse files Browse the repository at this point in the history
Rewrite the roundtrip() function to retry the request until it succeeds
or the deadline expires. Hopefully, this makes the cert tests more
robust on travis.
  • Loading branch information
magiconair committed Jan 9, 2018
1 parent a8b9a70 commit 10e5102
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions cert/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,20 +594,25 @@ func roundtrip(serverName string, srvConfig *tls.Config, client *http.Client) (c
// configure SNI
client.Transport.(*http.Transport).TLSClientConfig.ServerName = serverName

// give the tls server some time to start up
time.Sleep(10 * time.Millisecond)
deadline := time.Now().Add(500 * time.Millisecond)
for time.Now().Before(deadline) {
time.Sleep(25 * time.Millisecond)

resp, err := client.Get(srv.URL)
if err != nil {
return 0, "", err
}
defer resp.Body.Close()
var resp *http.Response
resp, err = client.Get(srv.URL)
if err != nil {
continue
}

data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return 0, "", err
var data []byte
data, err = ioutil.ReadAll(resp.Body)
if err != nil {
continue
}
resp.Body.Close()
return resp.StatusCode, string(data), nil
}
return resp.StatusCode, string(data), nil
return
}

// http11Client returns an HTTP client which can only
Expand Down

0 comments on commit 10e5102

Please sign in to comment.