@@ -334,6 +334,58 @@ func TestHystrixHTTPClientRetriesGetOnFailure5xx(t *testing.T) {
334334 assert .Equal (t , "{ \" response\" : \" something went wrong\" }" , respBody (t , response ))
335335}
336336
337+ func TestHystrixHTTPClientRetriesWithBudgetGetOnFailure5xx (t * testing.T ) {
338+ t .Parallel ()
339+
340+ count := 0
341+ backoffInterval := 1 * time .Millisecond
342+ maximumJitterInterval := 1 * time .Millisecond
343+
344+ client := NewClient (
345+ WithHTTPTimeout (10 * time .Millisecond ),
346+ WithCommandName ("some_command_name_5xx_with_budget" ),
347+ WithHystrixTimeout (10 * time .Millisecond ),
348+ WithMaxConcurrentRequests (100 ),
349+ WithErrorPercentThreshold (25 ),
350+ WithSleepWindow (100 ),
351+ WithRequestVolumeThreshold (100 ),
352+ WithRetryCount (4 ),
353+ WithRetryErrorBudgetToken (100 , 0.1 ),
354+ WithRetrier (heimdall .NewRetrier (heimdall .NewConstantBackoff (backoffInterval , maximumJitterInterval ))),
355+ )
356+
357+ dummyHandler := func (w http.ResponseWriter , r * http.Request ) {
358+ w .WriteHeader (http .StatusInternalServerError )
359+ _ , _ = w .Write ([]byte (`{ "response": "something went wrong" }` ))
360+ count = count + 1
361+ }
362+
363+ server := httptest .NewServer (http .HandlerFunc (dummyHandler ))
364+ defer server .Close ()
365+
366+ for attempt := range 10 { // under budget
367+ currCount := count
368+ response , err := client .Get (server .URL , http.Header {})
369+ require .NoError (t , err )
370+
371+ assert .Equal (t , 5 , count - currCount , "attempt #%d" , attempt )
372+ assert .NotNil (t , response )
373+ assert .Equal (t , http .StatusInternalServerError , response .StatusCode )
374+ assert .Equal (t , "{ \" response\" : \" something went wrong\" }" , respBody (t , response ))
375+ }
376+
377+ for attempt := range 10 { // over budget, no retry
378+ currCount := count
379+ response , err := client .Get (server .URL , http.Header {})
380+ require .NoError (t , err )
381+
382+ assert .Equal (t , 1 , count - currCount , "attempt #%d" , attempt )
383+ assert .NotNil (t , response )
384+ assert .Equal (t , http .StatusInternalServerError , response .StatusCode )
385+ assert .Equal (t , "{ \" response\" : \" something went wrong\" }" , respBody (t , response ))
386+ }
387+ }
388+
337389func BenchmarkHystrixHTTPClientRetriesGetOnFailure (b * testing.B ) {
338390 backoffInterval := 1 * time .Millisecond
339391 maximumJitterInterval := 1 * time .Millisecond
0 commit comments