645
645
end
646
646
end
647
647
648
+ @testset " Don't retry on internal exceptions" begin
649
+ kws = (retry_delays = [1 , 2 , 3 ], retries= 3 ) # ~ 6 secs
650
+ max_wait = 3
651
+
652
+ function test_finish_within (f, secs)
653
+ timedout = Ref (false )
654
+ t = Timer ((t)-> (timedout[] = true ), secs)
655
+ try
656
+ f ()
657
+ finally
658
+ close (t)
659
+ end
660
+ @test ! timedout[]
661
+ end
662
+
663
+ expected = ErrorException (" request" )
664
+ test_finish_within (max_wait) do
665
+ @test_throws expected ErrorRequest. get (" https://$httpbin /ip" ; request_exception= expected, kws... )
666
+ end
667
+ expected = ArgumentError (" request" )
668
+ test_finish_within (max_wait) do
669
+ @test_throws expected ErrorRequest. get (" https://$httpbin /ip" ; request_exception= expected, kws... )
670
+ end
671
+
672
+ test_finish_within (max_wait) do
673
+ expected = ErrorException (" stream" )
674
+ e = try
675
+ ErrorRequest. get (" https://$httpbin /ip" ; stream_exception= expected, kws... )
676
+ catch e
677
+ e
678
+ end
679
+ @assert e isa HTTP. RequestError
680
+ @test e. error == expected
681
+ end
682
+
683
+ test_finish_within (max_wait) do
684
+ expected = ArgumentError (" stream" )
685
+ e = try
686
+ ErrorRequest. get (" https://$httpbin /ip" ; stream_exception= expected, kws... )
687
+ catch e
688
+ e
689
+ end
690
+ @assert e isa HTTP. RequestError
691
+ @test e. error == expected
692
+ end
693
+ end
694
+
648
695
@testset " Retry with ConnectError" begin
649
696
mktemp () do path, io
650
697
redirect_stdout (io) do
@@ -668,12 +715,41 @@ end
668
715
end
669
716
670
717
# isrecoverable tests
671
- @test HTTP. RetryRequest. isrecoverable (nothing )
672
- @test HTTP. RetryRequest. isrecoverable (ErrorException (" " ))
673
- @test HTTP. RetryRequest. isrecoverable (Sockets. DNSError (" localhost" , Base. UV_EAI_AGAIN))
674
- @test ! HTTP. RetryRequest. isrecoverable (Sockets. DNSError (" localhost" , Base. UV_EAI_NONAME))
675
- @test HTTP. RetryRequest. isrecoverable (HTTP. Exceptions. ConnectError (" http://localhost" , Sockets. DNSError (" localhost" , Base. UV_EAI_AGAIN)))
676
- @test ! HTTP. RetryRequest. isrecoverable (HTTP. Exceptions. ConnectError (" http://localhost" , Sockets. DNSError (" localhost" , Base. UV_EAI_NONAME)))
718
+ @test ! HTTP. RetryRequest. isrecoverable (nothing )
719
+
720
+ @test ! HTTP. RetryRequest. isrecoverable (ErrorException (" " ))
721
+ @test ! HTTP. RetryRequest. isrecoverable (ArgumentError (" yikes" ))
722
+ @test HTTP. RetryRequest. isrecoverable (ArgumentError (" stream is closed or unusable" ))
723
+
724
+ @test HTTP. RetryRequest. isrecoverable (HTTP. RequestError (nothing , ArgumentError (" stream is closed or unusable" )))
725
+ @test ! HTTP. RetryRequest. isrecoverable (HTTP. RequestError (nothing , ArgumentError (" yikes" )))
726
+
727
+ @test HTTP. RetryRequest. isrecoverable (CapturedException (ArgumentError (" stream is closed or unusable" ), Any[]))
728
+
729
+ recoverable_dns_error = Sockets. DNSError (" localhost" , Base. UV_EAI_AGAIN)
730
+ unrecoverable_dns_error = Sockets. DNSError (" localhost" , Base. UV_EAI_NONAME)
731
+ @test HTTP. RetryRequest. isrecoverable (recoverable_dns_error)
732
+ @test ! HTTP. RetryRequest. isrecoverable (unrecoverable_dns_error)
733
+ @test HTTP. RetryRequest. isrecoverable (HTTP. Exceptions. ConnectError (" http://localhost" , recoverable_dns_error))
734
+ @test ! HTTP. RetryRequest. isrecoverable (HTTP. Exceptions. ConnectError (" http://localhost" , unrecoverable_dns_error))
735
+ @test HTTP. RetryRequest. isrecoverable (CompositeException ([
736
+ recoverable_dns_error,
737
+ HTTP. Exceptions. ConnectError (" http://localhost" , recoverable_dns_error),
738
+ ]))
739
+ @test HTTP. RetryRequest. isrecoverable (CompositeException ([
740
+ recoverable_dns_error,
741
+ HTTP. Exceptions. ConnectError (" http://localhost" , recoverable_dns_error),
742
+ CompositeException ([recoverable_dns_error])
743
+ ]))
744
+ @test ! HTTP. RetryRequest. isrecoverable (CompositeException ([
745
+ recoverable_dns_error,
746
+ HTTP. Exceptions. ConnectError (" http://localhost" , unrecoverable_dns_error),
747
+ ]))
748
+ @test ! HTTP. RetryRequest. isrecoverable (CompositeException ([
749
+ recoverable_dns_error,
750
+ HTTP. Exceptions. ConnectError (" http://localhost" , recoverable_dns_error),
751
+ CompositeException ([unrecoverable_dns_error])
752
+ ]))
677
753
end
678
754
679
755
findnewline (bytes) = something (findfirst (== (UInt8 (' \n ' )), bytes), 0 )
0 commit comments