2025-06-17 16:50:54 -04:00
|
|
|
"""Testing the the cluster."""
|
|
|
|
|
|
|
|
|
|
from unittest import IsolatedAsyncioTestCase
|
2025-06-18 16:15:53 -04:00
|
|
|
from uuid import uuid4
|
2025-06-17 16:50:54 -04:00
|
|
|
from aiohttp import ClientSession
|
2025-06-18 16:15:53 -04:00
|
|
|
from release_tests.support import ADDR
|
2025-06-17 16:50:54 -04:00
|
|
|
from release_tests.support.cluster import Cluster
|
|
|
|
|
|
2025-06-17 16:56:04 -04:00
|
|
|
|
2025-06-17 16:50:54 -04:00
|
|
|
class ClusterTC(IsolatedAsyncioTestCase):
|
|
|
|
|
"""Test for the MoreThanText cluster."""
|
|
|
|
|
|
|
|
|
|
async def test_create_default_cluster(self):
|
|
|
|
|
"""create a complete two server cluster."""
|
|
|
|
|
cluster = Cluster()
|
|
|
|
|
await cluster.start()
|
|
|
|
|
async with ClientSession() as session:
|
|
|
|
|
url = cluster.translate.baseurl
|
|
|
|
|
async with session.get(url) as resp:
|
|
|
|
|
text = await resp.text()
|
|
|
|
|
self.assertEqual(resp.status, 200, text)
|
|
|
|
|
self.assertEqual(len(cluster.servers), 2)
|
|
|
|
|
for server in cluster.servers:
|
|
|
|
|
url = server.baseurl
|
|
|
|
|
async with session.get(url) as resp:
|
|
|
|
|
text = await resp.text()
|
|
|
|
|
self.assertEqual(resp.status, 200, text)
|
|
|
|
|
await cluster.stop()
|
2025-06-18 16:15:53 -04:00
|
|
|
|
|
|
|
|
async def test_server_numbers(self):
|
|
|
|
|
"""Control the number of servers."""
|
|
|
|
|
count = 3
|
|
|
|
|
cluster = Cluster(num=count)
|
2025-06-22 17:04:37 -04:00
|
|
|
await cluster.start()
|
2025-06-18 16:15:53 -04:00
|
|
|
self.assertEqual(len(cluster.servers), count)
|
2025-06-22 17:04:37 -04:00
|
|
|
await cluster.cleanup()
|
2025-06-18 16:15:53 -04:00
|
|
|
|
|
|
|
|
async def test_set_translation_mocking(self):
|
|
|
|
|
"""Is the translation mocking setup"""
|
|
|
|
|
transurl = f"/{uuid4()}"
|
|
|
|
|
reply = str(uuid4())
|
|
|
|
|
cluster = Cluster(transurl=transurl, transreplies=[reply])
|
|
|
|
|
await cluster.start()
|
|
|
|
|
async with ClientSession() as session:
|
|
|
|
|
url = f"http://{ADDR}:{cluster.translate.port}{transurl}"
|
|
|
|
|
async with session.get(url) as resp:
|
|
|
|
|
text = await resp.text()
|
|
|
|
|
self.assertEqual(resp.status, 200, text)
|
|
|
|
|
await cluster.stop()
|
|
|
|
|
|
|
|
|
|
async def test_get_responses(self):
|
|
|
|
|
"""Get pulls responsre from each server"""
|
|
|
|
|
count = 4
|
|
|
|
|
cluster = Cluster(num=count)
|
|
|
|
|
await cluster.start()
|
|
|
|
|
resp = await cluster.get("/")
|
|
|
|
|
self.assertEqual(len(resp), count)
|
|
|
|
|
await cluster.stop()
|