Skip to content

Commit 792d597

Browse files
author
Andrei Neagu
committed
added test for multiple namespaces with redis store
1 parent 85cdd6b commit 792d597

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

packages/service-library/tests/long_running_tasks/test_long_running_tasks__store.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,51 @@ async def test_workflow(
9090
await store.set_as_cancelled(task_data.task_id, task_data.task_context)
9191

9292
assert await store.get_cancelled() == {task_data.task_id: task_data.task_context}
93+
94+
95+
@pytest.fixture
96+
async def redis_stores(
97+
redis_service: RedisSettings,
98+
get_redis_client_sdk: Callable[
99+
[RedisDatabase], AbstractAsyncContextManager[RedisClientSDK]
100+
],
101+
) -> AsyncIterable[list[RedisStore]]:
102+
stores: list[RedisStore] = [
103+
RedisStore(redis_settings=redis_service, namespace=f"test-{i}")
104+
for i in range(5)
105+
]
106+
for store in stores:
107+
await store.setup()
108+
109+
yield stores
110+
111+
for store in stores:
112+
await store.teardown()
113+
114+
# triggers cleanup of all redis data
115+
async with get_redis_client_sdk(RedisDatabase.LONG_RUNNING_TASKS):
116+
pass
117+
118+
119+
async def test_workflow_multiple_redis_stores_with_different_namespaces(
120+
redis_stores: list[RedisStore], get_task_data: Callable[[], TaskData]
121+
):
122+
task_data = get_task_data()
123+
124+
for store in redis_stores:
125+
assert await store.list_tasks_data() == []
126+
assert await store.get_cancelled() == {}
127+
128+
for store in redis_stores:
129+
await store.set_task_data(task_data.task_id, task_data)
130+
await store.set_as_cancelled(task_data.task_id, None)
131+
132+
for store in redis_stores:
133+
assert await store.list_tasks_data() == [task_data]
134+
assert await store.get_cancelled() == {task_data.task_id: None}
135+
136+
for store in redis_stores:
137+
await store.delete_task_data(task_data.task_id)
138+
139+
for store in redis_stores:
140+
assert await store.list_tasks_data() == []

0 commit comments

Comments
 (0)