From 930e016089c823532b86efe79f69581351c7afc2 Mon Sep 17 00:00:00 2001 From: Vladyslav Fenchak Date: Wed, 30 Mar 2022 21:30:46 +0200 Subject: [PATCH] ISSUE #78 --- .../test_discovery/dataset.py | 11 +++++ .../test_views/test_microservice.py | 40 ++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/tests/test_api_gateway/test_discovery/dataset.py b/tests/test_api_gateway/test_discovery/dataset.py index 6ef6b34..71c44ce 100644 --- a/tests/test_api_gateway/test_discovery/dataset.py +++ b/tests/test_api_gateway/test_discovery/dataset.py @@ -18,3 +18,14 @@ def generate_record(name): "endpoints": [["GET", f"test_endpoint_{name}"], ["POST", f"test_endpoint_{name}"]]} return record + + +def generate_record_old(x): + ip = socket.inet_ntoa(struct.pack('>I', random.randint(1, 0xffffffff))) + port = random.randint(1, 9999) + name = f"microservice_{x}" + + record = {"address": f"{ip}", "port": port, + "endpoints": [["GET", f"test_endpoint_{name}"], ["POST", f"test_endpoint_{name}"]]} + + return name, record diff --git a/tests/test_api_gateway/test_discovery/test_views/test_microservice.py b/tests/test_api_gateway/test_discovery/test_views/test_microservice.py index 5023c9a..34629c2 100644 --- a/tests/test_api_gateway/test_discovery/test_views/test_microservice.py +++ b/tests/test_api_gateway/test_discovery/test_views/test_microservice.py @@ -4,14 +4,14 @@ AioHTTPTestCase, unittest_run_loop, ) -import time from minos.api_gateway.common import ( MinosConfig, ) from minos.api_gateway.discovery import ( DiscoveryService, ) -from tests.test_api_gateway.test_discovery.dataset import generate_record, generate_random_microservice_names +from tests.test_api_gateway.test_discovery.dataset import generate_record, generate_random_microservice_names, \ + generate_record_old from tests.utils import ( BASE_PATH, ) @@ -80,6 +80,42 @@ async def test_bulk_update(self): self.assertEqual(record['body']['port'], int(body["port"])) self.assertEqual(record['name'], body["name"]) + async def test_bulk_update_2(self): + expected = list() + tasks = list() + # Create new records + for x in range(50): + name, body = generate_record_old(x) + tasks.append(self.client.post(f"/microservices/{name}", json=body)) + + results = await asyncio.gather(*tasks) + + for result in results: + self.assertEqual(201, result.status) + + tasks = list() + for x in range(50): + name, body = generate_record_old(x) + expected.append({"name": name, "path": f"/microservices/{name}", "body": body}) + tasks.append(self.client.post(f"/microservices/{name}", json=body)) + + results = await asyncio.gather(*tasks) + + for result in results: + self.assertEqual(201, result.status) + + for record in expected: + response = await self.client.get( + f"/microservices?verb={record['body']['endpoints'][0][0]}&path={record['body']['endpoints'][0][1]}") + + self.assertEqual(200, response.status) + + body = await response.json() + + self.assertEqual(record['body']['address'], body["address"]) + self.assertEqual(int(record['body']['port']), int(body["port"])) + self.assertEqual(record['name'], body["name"]) + @unittest_run_loop async def test_post_missing_param(self): name = "test_name"