Skip to content

Commit

Permalink
fixes concurrency test
Browse files Browse the repository at this point in the history
  • Loading branch information
felipao-mx committed Oct 14, 2023
1 parent 42b9f7e commit 4205e9d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions fast_agave/tasks/sqs_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ async def run_task(
) -> None:
delete_message = True
try:
# breakpoint()
await task_func(body)
except RetryTask as retry:
delete_message = message_receive_count >= max_retries + 1
Expand Down
13 changes: 6 additions & 7 deletions tests/tasks/test_sqs_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,21 +381,19 @@ async def test_concurrency_controller(
sqs_client,
) -> None:
message_id = str(uuid.uuid4())
test_message = dict(id=message_id, name='fast-agave')
test_message = dict(id='message_id', name='fast-agave')
for i in range(5):
await sqs_client.send_message(
MessageBody=json.dumps(test_message),
MessageGroupId=message_id,
)

max_running_tasks = 0
async_mock_function = AsyncMock()

async def task_counter(_: Dict) -> None:
nonlocal max_running_tasks
async def task_counter(data: Dict) -> None:
await asyncio.sleep(1)
running_tasks = len(await get_running_fast_agave_tasks())
if running_tasks > max_running_tasks:
max_running_tasks = running_tasks
await async_mock_function(running_tasks)

await task(
queue_url=sqs_client.queue_url,
Expand All @@ -406,4 +404,5 @@ async def task_counter(_: Dict) -> None:
max_concurrent_tasks=2,
)(task_counter)()

assert max_running_tasks == 2
running_tasks = [call[0] for call, _ in async_mock_function.call_args_list]
assert max(running_tasks) == 2

0 comments on commit 4205e9d

Please sign in to comment.