@@ -17,6 +17,8 @@ import (
1717 "github.com/wjdp/htmltest/issues"
1818 "github.com/wjdp/htmltest/output"
1919 "github.com/wjdp/htmltest/refcache"
20+
21+ "github.com/hashicorp/go-retryablehttp"
2022 "gopkg.in/seborama/govcr.v4"
2123)
2224
@@ -27,7 +29,7 @@ const vcrCassetteBasePath string = "fixtures/vcr"
2729// tests are run.
2830type HTMLTest struct {
2931 opts Options
30- httpClient * http .Client
32+ httpClient * retryablehttp .Client
3133 httpChannel chan bool // Buffer used to limit concurrent http requests
3234 hostChannels map [string ]chan bool // Buffers used to limit concurrent http requests per host
3335 documentStore htmldoc.DocumentStore
@@ -82,13 +84,22 @@ func Test(optsUser map[string]interface{}) (*HTMLTest, error) {
8284 TLSNextProto : make (map [string ]func (authority string , c * tls.Conn ) http.RoundTripper ),
8385 TLSClientConfig : & tls.Config {InsecureSkipVerify : hT .opts .IgnoreSSLVerify },
8486 }
85- hT .httpClient = & http.Client {
87+
88+ client := & http.Client {
8689 // Durations are in nanoseconds
8790 Transport : transport ,
8891 Timeout : time .Duration (hT .opts .ExternalTimeout ) * time .Second ,
8992 CheckRedirect : setRedirectLimitCheck (hT ),
9093 }
9194
95+ hT .httpClient = retryablehttp .NewClient ()
96+ hT .httpClient .HTTPClient = client
97+
98+ // Limit retry attempts during testing
99+ hT .httpClient .RetryMax = 2
100+ hT .httpClient .RetryWaitMax = 10 * time .Millisecond
101+ hT .httpClient .RetryWaitMin = 1 * time .Millisecond
102+
92103 // If enabled (unit tests only) patch in govcr to the httpClient
93104 var vcr * govcr.VCRControlPanel
94105 if hT .opts .VCREnable {
@@ -97,12 +108,12 @@ func Test(optsUser map[string]interface{}) (*HTMLTest, error) {
97108 // Build VCR
98109 vcr = govcr .NewVCR (hT .opts .FilePath ,
99110 & govcr.VCRConfig {
100- Client : hT .httpClient ,
111+ Client : hT .httpClient . HTTPClient ,
101112 CassettePath : path .Join (vcrCassetteBasePath , cassettePath ),
102113 })
103114
104115 // Inject VCR's http.Client wrapper
105- hT .httpClient = vcr .Client
116+ hT .httpClient . HTTPClient = vcr .Client
106117 }
107118
108119 // Make buffered channel to act as concurrency limiter
0 commit comments