test(storage): add retry to GCS call in postpolicy test
Fixes flakiness
@@ -457,6 +457,7 @@ func TestPostPolicyV4(t *testing.T) {
// policy.Fields. We test that this actually works against the live service
// using the policy generated by the sample.
+ testutil.Retry(t, 10, time.Second, func(r *testutil.R) {
// Create a form using the returned post policy.
formBuf := new(bytes.Buffer)
mw := multipart.NewWriter(formBuf)
@@ -482,30 +483,32 @@ func TestPostPolicyV4(t *testing.T) {
// Compose the HTTP request.
req, err := http.NewRequest("POST", policy.URL, formBuf)
if err != nil {
- t.Fatalf("failed to compose HTTP request: %v", err)
+ t.Errorf("failed to compose HTTP request: %v", err)
}
req.Header.Set("Content-Type", mw.FormDataContentType())
// Dump the request for logging.
requestDump, err := httputil.DumpRequest(req, true)
if err != nil {
- t.Logf("requestDump: %v", err)
+ r.Logf("requestDump: %v", err)
}
+ // Make request.
res, err := http.DefaultClient.Do(req)
if err != nil {
- t.Fatalf("client.Do: %v", err)
+ r.Errorf("client.Do: %v", err)
}
if g, w := res.StatusCode, 204; g != w {
responseDump, _ := httputil.DumpResponse(res, true)
- t.Errorf("status code in response mismatch: got %d want %d\nRequest: %v\n\nResponse: %s\n",
+ r.Errorf("status code in response mismatch: got %d want %d\nRequest: %v\n\nResponse: %s\n",
g, w, string(requestDump), responseDump)
}
io.Copy(ioutil.Discard, res.Body)
if err := res.Body.Close(); err != nil {
- t.Errorf("Body.Close: %v", err)
+ r.Errorf("Body.Close: %v", err)
}
+ })
// Verify that the file was uploaded by reading back its attributes.
bkt := client.Bucket(bucketName)
