Skip to content

Commit

Permalink
ISSUE #78
Browse files Browse the repository at this point in the history
  • Loading branch information
vladyslav-fenchak committed Mar 30, 2022
1 parent 0034970 commit 930e016
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
11 changes: 11 additions & 0 deletions tests/test_api_gateway/test_discovery/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 930e016

Please sign in to comment.