Tests for chat fail in 0.01% of cases multi-worker #11

Open
opened 2025-07-09 12:01:41 +02:00 by aleksa-radojicic · 0 comments
aleksa-radojicic commented 2025-07-09 12:01:41 +02:00 (Migrated from github.com)

When running a server using gunicorn -w 4 -k uvicorn.workers.UvicornWorker --capture-output app.main:app or fastapi run --workers 4 tests fail in approximately 4/10,000 cases.

Command used for testing: pytest -m websocket --count=10000

gunicorn -w 4 -k uvicorn.workers.UvicornWorker --error-logfile blarka.log --capture-output app.main:app (browser was on, maybe it did some requests)
FAILED app/tests/api/routes/test_message.py::test_self_socket[2452-10000] - AssertionError: assert 'Client #f127...left the chat' == 'Client #f127...ered the chat'
FAILED app/tests/api/routes/test_message.py::test_self_socket[4096-10000] - AssertionError: assert 'Client #f127...left the chat' == 'Client #f127...ered the chat'
FAILED app/tests/api/routes/test_message.py::test_self_socket[5342-10000] - AssertionError: assert 'Client #f127...left the chat' == 'Client #f127...ered the chat'

gunicorn -w 4 -k uvicorn.workers.UvicornWorker --error-logfile blarka.log --capture-output app.main:app
FAILED app/tests/api/routes/test_message.py::test_self_socket[2086-10000] - AssertionError: assert 'Client #d944...left the chat' == 'Client #d944...ered the chat'
FAILED app/tests/api/routes/test_message.py::test_self_socket[6078-10000] - AssertionError: assert 'Client #d944...left the chat' == 'Client #d944...ered the chat'
FAILED app/tests/api/routes/test_message.py::test_two_sockets[7891-10000] - AssertionError: assert UUID('d9441e81-df02-43f2-8111-4187217e8476') == UUID('70c64214-1309-...

gunicorn -w 4 -k uvicorn.workers.UvicornWorker --error-logfile file.log --capture-output -b 127.0.0.1:8000 app.main:app (browser was on, maybe it did some requests)
FAILED app/tests/api/routes/test_message.py::test_self_socket[4532-10000] - AssertionError: assert 'Client #fe46...left the chat' == 'Client #fe46...ered the chat'
FAILED app/tests/api/routes/test_message.py::test_self_socket[9079-10000] - AssertionError: assert 'Client #fe46...left the chat' == 'Client #fe46...ered the chat'
FAILED app/tests/api/routes/test_message.py::test_two_sockets[536-10000] - AssertionError: assert UUID('fe461836-0a03-4371-845c-20ef80fc097c') == UUID('495495a9-0505-...
FAILED app/tests/api/routes/test_message.py::test_two_sockets[1703-10000] - AssertionError: assert 'Client #fe46...left the chat' == 'Client #fe46...ered the chat'
FAILED app/tests/api/routes/test_message.py::test_two_sockets[1795-10000] - AssertionError: assert 'Client #fe46...left the chat' == 'Client #fe46...ered the chat'
FAILED app/tests/api/routes/test_message.py::test_two_sockets[7657-10000] - AssertionError: assert 'Client #fe46...left the chat' == 'Client #fe46...ered the chat'
FAILED app/tests/api/routes/test_message.py::test_two_sockets[7660-10000] - AssertionError: assert UUID('fe461836-0a03-4371-845c-20ef80fc097c') == UUID('495495a9-0505-...

fastapi run --workers 4
FAILED app/tests/api/routes/test_message.py::test_self_socket[4878-10000] - AssertionError: assert 'Client #81ca...left the chat' == 'Client #81ca...ered the chat'
FAILED app/tests/api/routes/test_message.py::test_two_sockets[5109-10000] - AssertionError: assert 'Client #81ca...left the chat' == 'Client #81ca...ered the chat'

I am not sure what causes this error, because when running on a single worker all tests pass for count of 20000.

When running a server using `gunicorn -w 4 -k uvicorn.workers.UvicornWorker --capture-output app.main:app` or `fastapi run --workers 4` tests fail in approximately 4/10,000 cases. Command used for testing: `pytest -m websocket --count=10000` ```txt gunicorn -w 4 -k uvicorn.workers.UvicornWorker --error-logfile blarka.log --capture-output app.main:app (browser was on, maybe it did some requests) FAILED app/tests/api/routes/test_message.py::test_self_socket[2452-10000] - AssertionError: assert 'Client #f127...left the chat' == 'Client #f127...ered the chat' FAILED app/tests/api/routes/test_message.py::test_self_socket[4096-10000] - AssertionError: assert 'Client #f127...left the chat' == 'Client #f127...ered the chat' FAILED app/tests/api/routes/test_message.py::test_self_socket[5342-10000] - AssertionError: assert 'Client #f127...left the chat' == 'Client #f127...ered the chat' gunicorn -w 4 -k uvicorn.workers.UvicornWorker --error-logfile blarka.log --capture-output app.main:app FAILED app/tests/api/routes/test_message.py::test_self_socket[2086-10000] - AssertionError: assert 'Client #d944...left the chat' == 'Client #d944...ered the chat' FAILED app/tests/api/routes/test_message.py::test_self_socket[6078-10000] - AssertionError: assert 'Client #d944...left the chat' == 'Client #d944...ered the chat' FAILED app/tests/api/routes/test_message.py::test_two_sockets[7891-10000] - AssertionError: assert UUID('d9441e81-df02-43f2-8111-4187217e8476') == UUID('70c64214-1309-... gunicorn -w 4 -k uvicorn.workers.UvicornWorker --error-logfile file.log --capture-output -b 127.0.0.1:8000 app.main:app (browser was on, maybe it did some requests) FAILED app/tests/api/routes/test_message.py::test_self_socket[4532-10000] - AssertionError: assert 'Client #fe46...left the chat' == 'Client #fe46...ered the chat' FAILED app/tests/api/routes/test_message.py::test_self_socket[9079-10000] - AssertionError: assert 'Client #fe46...left the chat' == 'Client #fe46...ered the chat' FAILED app/tests/api/routes/test_message.py::test_two_sockets[536-10000] - AssertionError: assert UUID('fe461836-0a03-4371-845c-20ef80fc097c') == UUID('495495a9-0505-... FAILED app/tests/api/routes/test_message.py::test_two_sockets[1703-10000] - AssertionError: assert 'Client #fe46...left the chat' == 'Client #fe46...ered the chat' FAILED app/tests/api/routes/test_message.py::test_two_sockets[1795-10000] - AssertionError: assert 'Client #fe46...left the chat' == 'Client #fe46...ered the chat' FAILED app/tests/api/routes/test_message.py::test_two_sockets[7657-10000] - AssertionError: assert 'Client #fe46...left the chat' == 'Client #fe46...ered the chat' FAILED app/tests/api/routes/test_message.py::test_two_sockets[7660-10000] - AssertionError: assert UUID('fe461836-0a03-4371-845c-20ef80fc097c') == UUID('495495a9-0505-... fastapi run --workers 4 FAILED app/tests/api/routes/test_message.py::test_self_socket[4878-10000] - AssertionError: assert 'Client #81ca...left the chat' == 'Client #81ca...ered the chat' FAILED app/tests/api/routes/test_message.py::test_two_sockets[5109-10000] - AssertionError: assert 'Client #81ca...left the chat' == 'Client #81ca...ered the chat' ``` I am not sure what causes this error, because when running on a single worker all tests pass for count of 20000.
Commenting is not possible because the repository is archived.
No milestone
No project
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
radoyitsa/chat-app-fast-api#11
No description provided.