| 
692 | 692 |     end  | 
693 | 693 | end  | 
694 | 694 | 
 
  | 
 | 695 | +@testset "Connection TimeoutException is retried" begin  | 
 | 696 | +    # Since our request fails and we don't get to see the response, we  | 
 | 697 | +    # add this layer just after the retry layer to capture the context  | 
 | 698 | +    # of the request which we can use to test that we attempted the retries  | 
 | 699 | +    function test_context_layer(handler)  | 
 | 700 | +        return function(req; test_context::Dict, kw...)  | 
 | 701 | +            merge!(test_context, req.context)  | 
 | 702 | +            return handler(req; kw...)  | 
 | 703 | +        end  | 
 | 704 | +    end  | 
 | 705 | + | 
 | 706 | +    test_context = Dict{Symbol,Any}()  | 
 | 707 | +    try  | 
 | 708 | +        HTTP.pushlayer!(test_context_layer)  | 
 | 709 | +        # 10.0.0.0 is non-routeable and will result in a connection timeout  | 
 | 710 | +        HTTP.get("http://10.0.0.0", connect_timeout=1, retries=3, retry_delays=[0.1, 0.1, 0.1], test_context=test_context)  | 
 | 711 | +    catch e  | 
 | 712 | +        @assert e isa HTTP.ConnectError  | 
 | 713 | +        @test e.error isa ConcurrentUtilities.TimeoutException  | 
 | 714 | +    finally  | 
 | 715 | +        HTTP.poplayer!()  | 
 | 716 | +    end  | 
 | 717 | + | 
 | 718 | +    @test test_context[:retrylimitreached]  | 
 | 719 | +    @test test_context[:retryattempt] == 3  | 
 | 720 | +    @test test_context[:connect_errors] == 3  | 
 | 721 | +end  | 
 | 722 | + | 
 | 723 | + | 
695 | 724 | @testset "Retry with ConnectError" begin  | 
696 | 725 |     mktemp() do path, io  | 
697 | 726 |         redirect_stdout(io) do  | 
 | 
717 | 746 |     # isrecoverable tests  | 
718 | 747 |     @test !HTTP.RetryRequest.isrecoverable(nothing)  | 
719 | 748 | 
 
  | 
 | 749 | +    @test HTTP.RetryRequest.isrecoverable(ConcurrentUtilities.TimeoutException(1.0))  | 
720 | 750 |     @test !HTTP.RetryRequest.isrecoverable(ErrorException(""))  | 
721 | 751 |     @test !HTTP.RetryRequest.isrecoverable(ArgumentError("yikes"))  | 
722 | 752 |     @test HTTP.RetryRequest.isrecoverable(ArgumentError("stream is closed or unusable"))  | 
 | 
0 commit comments