11# pylint: disable=locally-disabled, missing-class-docstring, missing-function-docstring, redefined-outer-name, too-few-public-methods, missing-module-docstring
22
33import asyncio
4- from multiprocessing import Process , Queue
4+ from multiprocessing import Manager , Process
55
66import pytest
77import requests
2828from tests .support .peer_socket import PeerSocket
2929from tests .support .webhook_notifier import run_server
3030
31- queue = Queue ()
31+ _manager = Manager ()
32+ _queues = _manager .list ()
3233
3334
3435@pytest .fixture (scope = "session" , autouse = True )
3536def start_server ():
36- flask_process = Process (target = run_server , args = (queue ,))
37+ flask_process = Process (target = run_server , args = (_queues ,))
3738 flask_process .start ()
3839
3940 session = requests .Session ()
@@ -55,6 +56,14 @@ def start_server():
5556 flask_process .terminate ()
5657
5758
59+ @pytest .fixture
60+ def event_queue ():
61+ q = _manager .Queue ()
62+ _queues .append (q )
63+ yield q
64+ _queues .remove (q )
65+
66+
5867class TestConnectingToServer :
5968 @pytest .mark .asyncio
6069 async def test_valid_credentials (self ):
@@ -97,7 +106,7 @@ def notifier():
97106class TestReceivingNotifications :
98107 @pytest .mark .asyncio
99108 async def test_room_created_deleted (
100- self , room_api : FishjamClient , notifier : FishjamNotifier
109+ self , room_api : FishjamClient , notifier : FishjamNotifier , event_queue
101110 ):
102111 event_checks = [ServerMessageRoomCreated , ServerMessageRoomDeleted ]
103112
@@ -117,11 +126,11 @@ async def test_room_created_deleted(
117126 notifier_task .cancel ()
118127
119128 for event in event_checks :
120- self .assert_event (event )
129+ self .assert_event (event , event_queue )
121130
122131 @pytest .mark .asyncio
123132 async def test_peer_connected_disconnected (
124- self , room_api : FishjamClient , notifier : FishjamNotifier
133+ self , room_api : FishjamClient , notifier : FishjamNotifier , event_queue
125134 ):
126135 event_checks = [
127136 ServerMessageRoomCreated ,
@@ -156,11 +165,11 @@ async def test_peer_connected_disconnected(
156165 peer_socket_task .cancel ()
157166
158167 for event in event_checks :
159- self .assert_event (event )
168+ self .assert_event (event , event_queue )
160169
161170 @pytest .mark .asyncio
162171 async def test_peer_connected_room_deleted (
163- self , room_api : FishjamClient , notifier : FishjamNotifier
172+ self , room_api : FishjamClient , notifier : FishjamNotifier , event_queue
164173 ):
165174 event_checks = [
166175 ServerMessageRoomCreated ,
@@ -193,8 +202,8 @@ async def test_peer_connected_room_deleted(
193202 peer_socket_task .cancel ()
194203
195204 for event in event_checks :
196- self .assert_event (event )
205+ self .assert_event (event , event_queue )
197206
198- def assert_event (self , event ):
199- data = queue .get (timeout = 5 )
207+ def assert_event (self , event , event_queue ):
208+ data = event_queue .get (timeout = 5 )
200209 assert data == event or isinstance (data , event )
0 commit comments