50 lines
2.1 KiB
Python
50 lines
2.1 KiB
Python
import time
|
|
|
|
from conftest import create_session, join_student
|
|
|
|
|
|
def test_load_simulation_50_students_full_quiz_and_autoclose(client, sample_pool):
|
|
sid = create_session(client, sample_pool)
|
|
rooms = client.app.state.rooms
|
|
sockets = []
|
|
try:
|
|
for idx in range(50):
|
|
join_student(client, sid, f"s{idx:02d}", f"Student {idx:02d}")
|
|
ws = client.websocket_connect(f"/ws/student/{sid}").__enter__()
|
|
sockets.append(ws)
|
|
assert ws.receive_json()["type"] == "state"
|
|
|
|
for question_idx in range(5):
|
|
client.portal.call(rooms.open_question, sid, question_idx, 1)
|
|
for ws in sockets:
|
|
assert ws.receive_json()["type"] == "question_open"
|
|
for idx, ws in enumerate(sockets):
|
|
answer = sample_pool["questions"][question_idx]["correct"] if idx % 3 else "A"
|
|
ws.send_json({"type": "submit", "question_idx": question_idx, "answer": answer})
|
|
assert ws.receive_json()["type"] == "submit_ack"
|
|
if question_idx == 4:
|
|
started = time.monotonic()
|
|
for ws in sockets:
|
|
message = ws.receive_json()
|
|
assert message["type"] == "question_closed"
|
|
assert time.monotonic() - started < 2
|
|
else:
|
|
client.portal.call(rooms.close_question, sid)
|
|
for ws in sockets:
|
|
assert ws.receive_json()["type"] == "question_closed"
|
|
client.portal.call(rooms.next_question, sid)
|
|
for ws in sockets:
|
|
assert ws.receive_json()["type"] == "between_questions"
|
|
|
|
client.portal.call(rooms.end_session, sid)
|
|
for ws in sockets:
|
|
assert ws.receive_json()["type"] == "session_ended"
|
|
|
|
csv_lines = client.get(f"/admin/api/sessions/{sid}/csv").text.strip().splitlines()
|
|
assert len(csv_lines) == 1 + 50 * 5
|
|
stats = client.get(f"/api/session/{sid}/stats?question_idx=4").json()
|
|
assert stats["top5"]
|
|
finally:
|
|
for ws in sockets:
|
|
ws.__exit__(None, None, None)
|