1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
package unit
import (
"context"
"net/http"
"testing"
"github.com/jarcoal/httpmock"
"github.com/linode/linodego"
"golang.org/x/net/http2"
)
func TestClient_NGINXRetry(t *testing.T) {
client := createMockClient(t)
// Recreate the NGINX LB error
nginxErrorFunc := func(request *http.Request) (*http.Response, error) {
resp := httpmock.NewStringResponse(400, "")
resp.Header.Add("Server", "nginx")
resp.Header.Set("Content-Type", "text/html")
return resp, nil
}
step := 0
httpmock.RegisterRegexpResponder("PUT",
mockRequestURL(t, "/profile"), func(request *http.Request) (*http.Response, error) {
if step == 0 {
step++
return nginxErrorFunc(request)
}
step++
return httpmock.NewJsonResponse(200, nil)
})
if _, err := client.UpdateProfile(context.Background(),
linodego.ProfileUpdateOptions{}); err != nil {
t.Fatal(err)
}
if step != 2 {
t.Fatalf("retry checks did not finish")
}
}
func TestClient_GoAwayRetry(t *testing.T) {
client := createMockClient(t)
step := 0
httpmock.RegisterRegexpResponder("PUT",
mockRequestURL(t, "/profile"), func(request *http.Request) (*http.Response, error) {
if step == 0 {
step++
return nil, http2.GoAwayError{}
}
step++
return httpmock.NewJsonResponse(200, nil)
})
if _, err := client.UpdateProfile(context.Background(),
linodego.ProfileUpdateOptions{}); err != nil {
t.Fatal(err)
}
if step != 2 {
t.Fatalf("retry checks did not finish")
}
}
|