fix: add timeouts to PayPal sandbox tests and pytest-timeout safety net
PayPal sandbox tests used requests.post/get() with no timeout parameter. When the CI runner at build.unturf.com cannot reach api-m.sandbox.paypal.com, these calls block until TCP timeout (minutes), stalling all xdist workers and causing the 1-hour CI timeout. - Add timeout=10 to all requests calls in PayPal sandbox tests - Add pytest-timeout with 60s default so no single test can hang the suite
This commit is contained in:
parent
c4926a8ab9
commit
cdc6582a8f
3 changed files with 14 additions and 6 deletions
|
|
@ -1773,7 +1773,8 @@ class AuthenticatedFunctionalTests(FunctionalTests):
|
||||||
f"{base_url}/v1/oauth2/token",
|
f"{base_url}/v1/oauth2/token",
|
||||||
headers={"Accept": "application/json", "Accept-Language": "en_US"},
|
headers={"Accept": "application/json", "Accept-Language": "en_US"},
|
||||||
data={"grant_type": "client_credentials"},
|
data={"grant_type": "client_credentials"},
|
||||||
auth=(paypal_client_id, paypal_secret)
|
auth=(paypal_client_id, paypal_secret),
|
||||||
|
timeout=10,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(auth_response.status_code, 200)
|
self.assertEqual(auth_response.status_code, 200)
|
||||||
|
|
@ -1803,7 +1804,8 @@ class AuthenticatedFunctionalTests(FunctionalTests):
|
||||||
f"{base_url}/v1/oauth2/token",
|
f"{base_url}/v1/oauth2/token",
|
||||||
headers={"Accept": "application/json", "Accept-Language": "en_US"},
|
headers={"Accept": "application/json", "Accept-Language": "en_US"},
|
||||||
data={"grant_type": "client_credentials"},
|
data={"grant_type": "client_credentials"},
|
||||||
auth=(paypal_client_id, paypal_secret)
|
auth=(paypal_client_id, paypal_secret),
|
||||||
|
timeout=10,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(auth_response.status_code, 200)
|
self.assertEqual(auth_response.status_code, 200)
|
||||||
|
|
@ -1827,7 +1829,8 @@ class AuthenticatedFunctionalTests(FunctionalTests):
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Authorization": f"Bearer {access_token}"
|
"Authorization": f"Bearer {access_token}"
|
||||||
},
|
},
|
||||||
json=order_json
|
json=order_json,
|
||||||
|
timeout=10,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(order_response.status_code, 201)
|
self.assertEqual(order_response.status_code, 201)
|
||||||
|
|
@ -1943,7 +1946,8 @@ class AuthenticatedFunctionalTests(FunctionalTests):
|
||||||
f"{base_url}/v1/oauth2/token",
|
f"{base_url}/v1/oauth2/token",
|
||||||
headers={"Accept": "application/json", "Accept-Language": "en_US"},
|
headers={"Accept": "application/json", "Accept-Language": "en_US"},
|
||||||
data={"grant_type": "client_credentials"},
|
data={"grant_type": "client_credentials"},
|
||||||
auth=(paypal_client_id, paypal_secret)
|
auth=(paypal_client_id, paypal_secret),
|
||||||
|
timeout=10,
|
||||||
)
|
)
|
||||||
|
|
||||||
access_token = auth_response.json()["access_token"]
|
access_token = auth_response.json()["access_token"]
|
||||||
|
|
@ -1961,7 +1965,8 @@ class AuthenticatedFunctionalTests(FunctionalTests):
|
||||||
"amount": {"currency_code": "USD", "value": "5.00"},
|
"amount": {"currency_code": "USD", "value": "5.00"},
|
||||||
"description": "Test retrieval order"
|
"description": "Test retrieval order"
|
||||||
}]
|
}]
|
||||||
}
|
},
|
||||||
|
timeout=10,
|
||||||
)
|
)
|
||||||
|
|
||||||
order_id = order_response.json()["id"]
|
order_id = order_response.json()["id"]
|
||||||
|
|
@ -1969,7 +1974,8 @@ class AuthenticatedFunctionalTests(FunctionalTests):
|
||||||
# Retrieve the order
|
# Retrieve the order
|
||||||
get_response = requests.get(
|
get_response = requests.get(
|
||||||
f"{base_url}/v2/checkout/orders/{order_id}",
|
f"{base_url}/v2/checkout/orders/{order_id}",
|
||||||
headers={"Authorization": f"Bearer {access_token}"}
|
headers={"Authorization": f"Bearer {access_token}"},
|
||||||
|
timeout=10,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(get_response.status_code, 200)
|
self.assertEqual(get_response.status_code, 200)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
[pytest]
|
[pytest]
|
||||||
testpaths = make_post_sell
|
testpaths = make_post_sell
|
||||||
python_files = test*.py
|
python_files = test*.py
|
||||||
|
timeout = 60
|
||||||
# Uncomment filterwarnings to suppress external library warnings
|
# Uncomment filterwarnings to suppress external library warnings
|
||||||
# filterwarnings =
|
# filterwarnings =
|
||||||
# # Ignore datetime.utcnow() deprecation from external libraries
|
# # Ignore datetime.utcnow() deprecation from external libraries
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
# testing.
|
# testing.
|
||||||
pytest
|
pytest
|
||||||
pytest-cov
|
pytest-cov
|
||||||
|
pytest-timeout # Per-test timeout safety net
|
||||||
pytest-xdist # Parallel test execution
|
pytest-xdist # Parallel test execution
|
||||||
nose
|
nose
|
||||||
mock
|
mock
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue