Debian Codegraph @

tests/functional/services/transfer/test_custom_retry_behavior.py

raw
1 import pytest
2
3 import globus_sdk
4 from globus_sdk.testing import RegisteredResponse
5
6
7 def test_transfer_client_will_retry_ordinary_502(client, mocksleep):
8 # turn on retries (fixture defaults off)
9 client.retry_config.max_retries = 1
10
11 RegisteredResponse(service="transfer", path="/foo", status=502, body="Uh-oh!").add()
12 RegisteredResponse(service="transfer", path="/foo", json={"status": "ok"}).add()
13
14 # no sign of an error in the client
15 res = client.get("/foo")
16 assert res.http_status == 200
17 assert res["status"] == "ok"
18
19 # there was a sleep (retry was triggered)
20 mocksleep.assert_called_once()
21
22
23 def test_transfer_client_will_not_retry_endpoint_error(client, mocksleep):
24 # turn on retries (fixture defaults off)
25 client.retry_config.max_retries = 1
26
27 RegisteredResponse(
28 service="transfer",
29 path="/do_a_gcp_thing",
30 status=502,
31 json={
32 "HTTP status": "502",
33 "code": "ExternalError.DirListingFailed.GCDisconnected",
34 "error_name": "Transfer API Error",
35 "message": "The GCP endpoint is not currently connected to Globus",
36 "request_id": "rhvcR0aHX",
37 },
38 ).add()
39 RegisteredResponse(
40 service="transfer", path="/do_a_gcp_thing", json={"status": "ok"}
41 ).add()
42
43 # no sign of an error in the client
44 with pytest.raises(globus_sdk.TransferAPIError) as excinfo:
45 client.get("/do_a_gcp_thing")
46 assert excinfo.value.http_status == 502
47
48 # there was no sleep (retry was not triggered)
49 mocksleep.assert_not_called()