As part of PR for issue #52 we found out that the PubSub being a singleton causes issue when multiple tasks of the same definition are applied simultaneously, whereby the return values of all tasks will become equal to the return value of the first task that returned i.e. we failed second the test below:
@pytest.mark.asyncio
async def test_serial_async_tasks_return_correctly(worker: "WorkerFixture"):
# Given that worker cli is run
await worker.start(app=simple_app.__name__)
# When multiple async tasks with different expected return value are applied serially
results_1 = await simple_app.wait.apply_async(t_s=1)
results_2 = await simple_app.wait.apply_async(t_s=2)
results_3 = await simple_app.wait.apply_async(t_s=3)
results_actual = [results_1, results_2, results_3]
# Then the results should be correct
results_expected = [1, 2, 3]
assert results_actual == results_expected
@pytest.mark.asyncio
async def test_concurrent_async_tasks_return_correctly(worker: "WorkerFixture"):
# Given that worker cli is run with "--concurrency 2" option
await worker.start(app=simple_app.__name__, concurrency=2)
# When multiple async tasks with different expected return value are applied simultaneously
results_actual = await asyncio.gather(
*[
simple_app.wait.apply_async(t_s=1),
simple_app.wait.apply_async(t_s=2),
simple_app.wait.apply_async(t_s=3),
],
)
# Then the results should be correct
results_expected = [1, 2, 3]
assert results_actual == results_expected
As part of PR for issue #52 we found out that the
PubSub
being a singleton causes issue when multiple tasks of the same definition are applied simultaneously, whereby the return values of all tasks will become equal to the return value of the first task that returned i.e. we failed second the test below: