Skip to content

Commit 930e016

Browse files
ISSUE #78
1 parent 0034970 commit 930e016

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

tests/test_api_gateway/test_discovery/dataset.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,14 @@ def generate_record(name):
1818
"endpoints": [["GET", f"test_endpoint_{name}"], ["POST", f"test_endpoint_{name}"]]}
1919

2020
return record
21+
22+
23+
def generate_record_old(x):
24+
ip = socket.inet_ntoa(struct.pack('>I', random.randint(1, 0xffffffff)))
25+
port = random.randint(1, 9999)
26+
name = f"microservice_{x}"
27+
28+
record = {"address": f"{ip}", "port": port,
29+
"endpoints": [["GET", f"test_endpoint_{name}"], ["POST", f"test_endpoint_{name}"]]}
30+
31+
return name, record

tests/test_api_gateway/test_discovery/test_views/test_microservice.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
AioHTTPTestCase,
55
unittest_run_loop,
66
)
7-
import time
87
from minos.api_gateway.common import (
98
MinosConfig,
109
)
1110
from minos.api_gateway.discovery import (
1211
DiscoveryService,
1312
)
14-
from tests.test_api_gateway.test_discovery.dataset import generate_record, generate_random_microservice_names
13+
from tests.test_api_gateway.test_discovery.dataset import generate_record, generate_random_microservice_names, \
14+
generate_record_old
1515
from tests.utils import (
1616
BASE_PATH,
1717
)
@@ -80,6 +80,42 @@ async def test_bulk_update(self):
8080
self.assertEqual(record['body']['port'], int(body["port"]))
8181
self.assertEqual(record['name'], body["name"])
8282

83+
async def test_bulk_update_2(self):
84+
expected = list()
85+
tasks = list()
86+
# Create new records
87+
for x in range(50):
88+
name, body = generate_record_old(x)
89+
tasks.append(self.client.post(f"/microservices/{name}", json=body))
90+
91+
results = await asyncio.gather(*tasks)
92+
93+
for result in results:
94+
self.assertEqual(201, result.status)
95+
96+
tasks = list()
97+
for x in range(50):
98+
name, body = generate_record_old(x)
99+
expected.append({"name": name, "path": f"/microservices/{name}", "body": body})
100+
tasks.append(self.client.post(f"/microservices/{name}", json=body))
101+
102+
results = await asyncio.gather(*tasks)
103+
104+
for result in results:
105+
self.assertEqual(201, result.status)
106+
107+
for record in expected:
108+
response = await self.client.get(
109+
f"/microservices?verb={record['body']['endpoints'][0][0]}&path={record['body']['endpoints'][0][1]}")
110+
111+
self.assertEqual(200, response.status)
112+
113+
body = await response.json()
114+
115+
self.assertEqual(record['body']['address'], body["address"])
116+
self.assertEqual(int(record['body']['port']), int(body["port"]))
117+
self.assertEqual(record['name'], body["name"])
118+
83119
@unittest_run_loop
84120
async def test_post_missing_param(self):
85121
name = "test_name"

0 commit comments

Comments
 (0)