Skip to content

Commit 362247a

Browse files
Fix tests
1 parent ea7bf25 commit 362247a

File tree

3 files changed

+32
-21
lines changed

3 files changed

+32
-21
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@ jobs:
5555
- name: Initialize Localtunnel
5656
id: tunnel
5757
run: |
58-
npx localtunnel --port 5000 > tunnel.log 2>&1 &
59-
58+
npm install -g localtunnel
59+
localtunnel --port 5000 > tunnel.log 2>&1 &
60+
6061
# Poll for the URL
61-
TIMEOUT=10
62+
TIMEOUT=15
6263
ELAPSED=0
6364
echo "Waiting for localtunnel to generate URL..."
64-
65+
6566
while ! grep -q "https://" tunnel.log; do
6667
if [ $ELAPSED -ge $TIMEOUT ]; then
6768
echo "Error: Localtunnel timed out after ${TIMEOUT}s"
@@ -71,7 +72,7 @@ jobs:
7172
sleep 1
7273
ELAPSED=$((ELAPSED + 1))
7374
done
74-
75+
7576
TUNNEL_URL=$(grep -o 'https://[^ ]*' tunnel.log | head -n 1)
7677
echo "url=$TUNNEL_URL" >> $GITHUB_OUTPUT
7778
echo "Localtunnel is live at: $TUNNEL_URL"

tests/support/webhook_notifier.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from fishjam import receive_binary
66

77
app = Flask(__name__)
8-
DATA_QUEUE = None
8+
QUEUES = None
99

1010

1111
@app.route("/", methods=["GET"])
@@ -17,12 +17,13 @@ def respond_default():
1717
def respond_root():
1818
data = request.get_data()
1919
msg = receive_binary(data)
20-
DATA_QUEUE.put(msg)
20+
for q in QUEUES:
21+
q.put(msg)
2122

2223
return Response(status=200)
2324

2425

25-
def run_server(queue):
26-
global DATA_QUEUE
27-
DATA_QUEUE = queue
26+
def run_server(queues):
27+
global QUEUES
28+
QUEUES = queues
2829
app.run(port=5000, host="0.0.0.0", use_reloader=False, debug=False, threaded=True)

tests/test_notifier.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# pylint: disable=locally-disabled, missing-class-docstring, missing-function-docstring, redefined-outer-name, too-few-public-methods, missing-module-docstring
22

33
import asyncio
4-
from multiprocessing import Process, Queue
4+
from multiprocessing import Manager, Process
55

66
import pytest
77
import requests
@@ -28,12 +28,13 @@
2828
from tests.support.peer_socket import PeerSocket
2929
from 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)
3536
def 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+
5867
class TestConnectingToServer:
5968
@pytest.mark.asyncio
6069
async def test_valid_credentials(self):
@@ -97,7 +106,7 @@ def notifier():
97106
class 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

Comments
 (0)