Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions lib/bindings/python/tests/test_kv_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

pytestmark = pytest.mark.pre_merge

runtime = None


@pytest.fixture(scope="module", autouse=True)
def setup_and_teardown():
Expand All @@ -50,12 +48,13 @@ def setup_and_teardown():
etcd.wait()


async def test_event_handler():
global runtime
if runtime is None:
loop = asyncio.get_running_loop()
runtime = DistributedRuntime(loop)
@pytest.fixture(scope="module")
async def distributed_runtime():
loop = asyncio.get_running_loop()
return DistributedRuntime(loop)


async def test_event_handler(distributed_runtime):
namespace = "kv_test"
component = "event"

Expand All @@ -64,7 +63,7 @@ async def test_event_handler():
event_publisher = EventPublisher(namespace, component, worker_id)

# indexer
kv_listener = runtime.namespace(namespace).component(component)
kv_listener = distributed_runtime.namespace(namespace).component(component)
await kv_listener.create_service()
indexer = KvIndexer(kv_listener)

Expand Down Expand Up @@ -160,15 +159,10 @@ def remove_event(self):
assert result == DynemoResult.OK


async def test_metrics_aggregator():
global runtime
if runtime is None:
loop = asyncio.get_running_loop()
runtime = DistributedRuntime(loop)

async def test_metrics_aggregator(distributed_runtime):
namespace = "kv_test"
component = "metrics"
kv_listener = runtime.namespace(namespace).component(component)
kv_listener = distributed_runtime.namespace(namespace).component(component)
await kv_listener.create_service()

# aggregator
Expand All @@ -185,8 +179,8 @@ async def test_metrics_aggregator():
"kv_total_blocks": 777,
}

# need 'create_taskk' to put publisher task in the background
asyncio.create_task(metrics_publisher(kv_listener, expected_metrics))
# need 'create_task' to put publisher task in the background
asyncio.create_task(metrics_publisher_task(kv_listener, expected_metrics))

# needs time for publisher to spawn up
for i in range(10):
Expand All @@ -205,7 +199,7 @@ async def test_metrics_aggregator():
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.publish(
expected_metrics["request_active_slots"],
Expand Down