Commit 6ba39b09 authored by GuanLuo's avatar GuanLuo Committed by GitHub
Browse files

chore: address comments for #35 (#53)

parent 19844fc0
...@@ -29,8 +29,6 @@ from dynamo.runtime import DistributedRuntime ...@@ -29,8 +29,6 @@ from dynamo.runtime import DistributedRuntime
pytestmark = pytest.mark.pre_merge pytestmark = pytest.mark.pre_merge
runtime = None
@pytest.fixture(scope="module", autouse=True) @pytest.fixture(scope="module", autouse=True)
def setup_and_teardown(): def setup_and_teardown():
...@@ -50,12 +48,13 @@ def setup_and_teardown(): ...@@ -50,12 +48,13 @@ def setup_and_teardown():
etcd.wait() etcd.wait()
async def test_event_handler(): @pytest.fixture(scope="module")
global runtime async def distributed_runtime():
if runtime is None: loop = asyncio.get_running_loop()
loop = asyncio.get_running_loop() return DistributedRuntime(loop)
runtime = DistributedRuntime(loop)
async def test_event_handler(distributed_runtime):
namespace = "kv_test" namespace = "kv_test"
component = "event" component = "event"
...@@ -64,7 +63,7 @@ async def test_event_handler(): ...@@ -64,7 +63,7 @@ async def test_event_handler():
event_publisher = EventPublisher(namespace, component, worker_id) event_publisher = EventPublisher(namespace, component, worker_id)
# indexer # indexer
kv_listener = runtime.namespace(namespace).component(component) kv_listener = distributed_runtime.namespace(namespace).component(component)
await kv_listener.create_service() await kv_listener.create_service()
indexer = KvIndexer(kv_listener) indexer = KvIndexer(kv_listener)
...@@ -160,15 +159,10 @@ class EventPublisher: ...@@ -160,15 +159,10 @@ class EventPublisher:
assert result == DynamoResult.OK assert result == DynamoResult.OK
async def test_metrics_aggregator(): async def test_metrics_aggregator(distributed_runtime):
global runtime
if runtime is None:
loop = asyncio.get_running_loop()
runtime = DistributedRuntime(loop)
namespace = "kv_test" namespace = "kv_test"
component = "metrics" component = "metrics"
kv_listener = runtime.namespace(namespace).component(component) kv_listener = distributed_runtime.namespace(namespace).component(component)
await kv_listener.create_service() await kv_listener.create_service()
# aggregator # aggregator
...@@ -185,8 +179,8 @@ async def test_metrics_aggregator(): ...@@ -185,8 +179,8 @@ async def test_metrics_aggregator():
"kv_total_blocks": 777, "kv_total_blocks": 777,
} }
# need 'create_taskk' to put publisher task in the background # need 'create_task' to put publisher task in the background
asyncio.create_task(metrics_publisher(kv_listener, expected_metrics)) asyncio.create_task(metrics_publisher_task(kv_listener, expected_metrics))
# needs time for publisher to spawn up # needs time for publisher to spawn up
for i in range(10): for i in range(10):
...@@ -205,7 +199,7 @@ async def test_metrics_aggregator(): ...@@ -205,7 +199,7 @@ async def test_metrics_aggregator():
assert endpoint.kv_total_blocks == expected_metrics["kv_total_blocks"] assert endpoint.kv_total_blocks == expected_metrics["kv_total_blocks"]
async def metrics_publisher(kv_listener, expected_metrics): async def metrics_publisher_task(kv_listener, expected_metrics):
metrics_publisher = KvMetricsPublisher() metrics_publisher = KvMetricsPublisher()
metrics_publisher.publish( metrics_publisher.publish(
expected_metrics["request_active_slots"], expected_metrics["request_active_slots"],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment