@@ -32,6 +32,7 @@ func TestRetry(t *testing.T) {
3232 failCode int
3333 failErr error
3434 response string
35+ expectError bool
3536 }{
3637 {
3738 name : "no retries" ,
@@ -49,6 +50,12 @@ func TestRetry(t *testing.T) {
4950 failErr : io .ErrUnexpectedEOF ,
5051 timesToFail : 1 ,
5152 },
53+ {
54+ name : "retry io.ErrUnexpectedEOF permanent" ,
55+ failErr : io .ErrUnexpectedEOF ,
56+ timesToFail : maxRetryAttempts + 1 ,
57+ expectError : true ,
58+ },
5259 }
5360 for _ , tt := range tests {
5461 t .Run (tt .name , func (t * testing.T ) {
@@ -60,15 +67,23 @@ func TestRetry(t *testing.T) {
6067 }
6168 c := NewClient (& http.Client {Transport : ft })
6269 s , err := c .Get ("" )
63- if err != nil {
70+ if tt .expectError && err == nil {
71+ t .Fatalf ("did not receive expected error" )
72+ } else if ! tt .expectError && err != nil {
6473 t .Fatalf ("unexpected error: %v" , err )
6574 }
66- if ft .called != ft .failedAttempts + 1 {
67- t .Fatalf ("failed %d times, want %d" , ft .called , ft .failedAttempts + 1 )
68- }
69- if s != tt .response {
75+
76+ expectedCount := ft .failedAttempts + 1
77+ if tt .expectError {
78+ expectedCount = ft .failedAttempts
79+ } else if s != tt .response {
80+ // Responses are only meaningful if err == nil
7081 t .Fatalf ("c.Get() = %q, want %q" , s , tt .response )
7182 }
83+
84+ if ft .called != expectedCount {
85+ t .Fatalf ("failed %d times, want %d" , ft .called , expectedCount )
86+ }
7287 })
7388 }
7489}
0 commit comments