-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_http_server_multi_test.py
35 lines (26 loc) · 1.41 KB
/
simple_http_server_multi_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import asyncio
import urllib.request
import uuid
async def send_request_and_collect_response(identifier):
url = 'http://localhost:9999'
headers = {'X-UUID': str(identifier)} # Include the UUID in the request headers
with urllib.request.urlopen(urllib.request.Request(url, headers=headers)) as response:
# Collect and return the response along with the identifier and response UUID
response_data = response.read().decode('utf-8')
print(f"Received response for identifier {identifier}: {response_data}")
return identifier, response_data
async def main():
identifiers = [uuid.uuid4() for _ in range(5000)]
expected_responses = {} # Dictionary to store expected responses with identifiers
# Send concurrent requests using asyncio.gather
tasks = [send_request_and_collect_response(identifier) for identifier in identifiers]
responses = await asyncio.gather(*tasks)
# Update expected_responses dictionary with the collected responses
print(responses)
for identifier, response in responses:
expected_responses[identifier] = response
# Perform assertions to ensure each client received the correct response
for identifier, expected_response in expected_responses.items():
# Assert that the received response contains the UUID
assert str(identifier) in expected_response, f"UUID mismatch for identifier {identifier}"
asyncio.run(main())