Skip to content

Commit

Permalink
Fix tests failing due to socketio connection issues (#2447)
Browse files Browse the repository at this point in the history
  • Loading branch information
matrss authored Aug 2, 2024
1 parent c35c31c commit 81fd6a3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import multiprocessing
import time
import urllib
import socketio
import mslib.mswms.mswms
import eventlet
import eventlet.wsgi
Expand Down Expand Up @@ -107,14 +108,26 @@ def mscolab_session_managers(mscolab_session_app):
return sockio, cm, fm


@pytest.fixture(scope="session")
# TODO: Having this fixture be autouse is a crutch. It seems like if it is not autouse some tests can bring the pytest
# processes objects into a state in which the MSColab server will have trouble starting the Flask-SocketIO server once
# it is forked. With autouse the fork happens first, before any test runs. After that, the pytest process can no longer
# affect the now-running server, thus mitigating the issue. This is my understanding at time of writing.
#
# This issue would also be avoided if the background server process wasn't started with multiprocessing and a fork, but
# with a real subprocess, which would solve some other issues (e.g. testing on Windows) as well.
@pytest.fixture(scope="session", autouse=True)
def mscolab_session_server(mscolab_session_app, mscolab_session_managers):
"""Session-scoped fixture that provides a running MSColab server.
This fixture should not be used in tests. Instead use :func:`mscolab_server`, which
handles per-test cleanup as well.
"""
with _running_eventlet_server(mscolab_session_app) as url:
# Wait until the Flask-SocketIO server is ready for connections
sio = socketio.Client()
sio.connect(url, retry=True)
sio.disconnect()
del sio
yield url


Expand Down

0 comments on commit 81fd6a3

Please sign in to comment.