from conftest import admin_login, join_student def test_load_simulation_50_students_full_quiz(client, sid, sample_pool): """50 students answer 5 questions; instructor drives transitions via the single 'advance_to_next' WS command.""" 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" # Start: opens Q0 from lobby. client.portal.call(rooms.advance_to_next, sid) for ws in sockets: assert ws.receive_json()["type"] == "question_open" for question_idx in range(5): 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" client.portal.call(rooms.advance_to_next, sid) for ws in sockets: first = ws.receive_json() assert first["type"] == "question_closed" second = ws.receive_json() expected_next = "question_open" if question_idx < 4 else "session_ended" assert second["type"] == expected_next admin_login(client) csv_lines = client.get("/admin/api/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)