Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: lobby fail lock up #550

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/lobby-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@empirica/core": patch
---

Fix lobby fail strategy and similar straight to exit steps cases.

There was a check for the presence of the `player.game` object in front of the
exit steps. If the game never starts, the `player.game` object is never
created, and the exit steps are never executed. This also addresses the case
where the player is never assigned a game at all (custom assignment).
10 changes: 10 additions & 0 deletions lib/@empirica/core/src/player/classic/react/EmpiricaContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,16 @@ function useGameReady() {
const players = usePlayers();
const game = useGame();

// Player was never even assigned to a game, so no game.
if (player && !player.get("gameID")) {
return true;
}

// Game never started, so no player.game.
if (player && game && !game.get("start")) {
return true;
}

if (!player || !players || !game || !player.game) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions tests/stress/experiment/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
},
"version": "0.0.0",
"volta": {
"node": "20.10.0",
"npm": "10.2.3"
"node": "20.12.0",
"npm": "10.5.0"
},
"engines": {
"node": ">= 20.12.0"
}
}
7 changes: 5 additions & 2 deletions tests/stress/experiment/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
"serve": "node --trace-warnings --enable-source-maps --unhandled-rejections=warn-with-error-code index.js"
},
"volta": {
"node": "20.10.0",
"npm": "10.2.3"
"node": "20.12.0",
"npm": "10.5.0"
},
"engines": {
"node": ">= 20.12.0"
}
}
43 changes: 41 additions & 2 deletions tests/stress/tests/lobby.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
/// <reference path="./index.d.ts" />

const { test } = require("@playwright/test");
import { Context } from "./context";
import { adminNewBatch, quickGame } from "./admin";
import { Context } from "./context";
import {
playerSignIn,
playerStart,
submitStage,
waitGameFinished,
Expand Down Expand Up @@ -42,7 +43,7 @@ test("lobby shared ignore", async ({ browser }) => {
lobbyConfig: {
name: "Fast shared ignore",
kind: "shared",
duration: 5_000_000_000,
duration: 2_000_000_000,
strategy: "ignore",
},
})
Expand All @@ -67,3 +68,41 @@ test("lobby shared ignore", async ({ browser }) => {

await ctx.close();
});

// This test is a test for the lobby with configuration shared/fail, which
// means that all players share a timer and we fail the game if not enough
// players to start the game.
// To test this, we set a very short duration for the lobby.
test("lobby shared fail", async ({ browser }) => {
const ctx = new Context(browser);

const playerCount = 2;
const roundCount = 1;
const stageCount = 2;

await ctx.start();
await ctx.addPlayers(playerCount);
ctx.players[0].logWS();
ctx.players[0].listenScope("game");
ctx.logMatching(/HERE/);

await ctx.applyAdmin(
adminNewBatch({
treatmentConfig: quickGame(playerCount, roundCount, stageCount),
lobbyConfig: {
name: "Fast shared fail",
kind: "shared",
duration: 2_000_000_000, // 2s, in ns...
strategy: "fail",
},
})
);

await ctx.players[0].apply(playerSignIn);
await ctx.players[0].screenshot("start-game");
await sleep(2500);
await ctx.players[0].screenshot("end-maybe");
await ctx.players[0].apply(waitGameFinished);

await ctx.close();
});
1 change: 1 addition & 0 deletions tests/stress/tests/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ function playerReceivedPrinter(actor) {
console.log(receive, "UNKNOWN", change["__typename"], change);
}
} catch (e) {
console.error(e);
console.log(receive, "FAIL", payload);
}
};
Expand Down
Loading