1- from concurrent .futures import ThreadPoolExecutor , as_completed
2-
31from policyengine_api_simulation_client import Client , AuthenticatedClient
42from policyengine_api_simulation_client .api .default import ping_ping_post
53from policyengine_api_simulation_client .models import PingRequest , PingResponse
64from policyengine_api_simulation_client .errors import UnexpectedStatus
75import backoff
86import httpx
9- import pytest
107
118
129@backoff .on_exception (
@@ -24,46 +21,3 @@ def test_ping(client: Client | AuthenticatedClient):
2421 response = ping_ping_post .sync (client = client , body = PingRequest (value = 12 ))
2522 assert isinstance (response , PingResponse )
2623 assert response .incremented == 13
27-
28-
29- @pytest .mark .beta_only
30- def test_ping_concurrent_requests (client : Client | AuthenticatedClient ):
31- """
32- Given a running simulation API
33- When 10 ping requests are sent simultaneously
34- Then all requests return successfully with correct incremented values.
35- """
36- # Given
37- num_requests = 10
38-
39- def make_ping_request (
40- value : int ,
41- ) -> tuple [int , PingResponse | None , Exception | None ]:
42- """Make a single ping request and return (value, response, error)."""
43- try :
44- response = ping_ping_post .sync (client = client , body = PingRequest (value = value ))
45- return (value , response , None )
46- except Exception as e :
47- return (value , None , e )
48-
49- # When - send 10 requests simultaneously
50- results = []
51- with ThreadPoolExecutor (max_workers = num_requests ) as executor :
52- futures = {
53- executor .submit (make_ping_request , i ): i for i in range (num_requests )
54- }
55- for future in as_completed (futures ):
56- results .append (future .result ())
57-
58- # Then - all requests should succeed
59- errors = [(v , e ) for v , r , e in results if e is not None ]
60- assert len (errors ) == 0 , f"Some requests failed: { errors } "
61-
62- # And - all responses should have correct incremented values
63- for value , response , error in results :
64- assert isinstance (response , PingResponse ), (
65- f"Request { value } did not return PingResponse"
66- )
67- assert response .incremented == value + 1 , (
68- f"Request { value } returned wrong increment: expected { value + 1 } , got { response .incremented } "
69- )
0 commit comments