fix: resume saved lobbies when host capacity is full

This commit is contained in:
2026-09-29 02:58:48 +00:00
parent 9b9aafefc1
commit 9d5a046b40
2 changed files with 26 additions and 1 deletions

View File

@@ -190,6 +190,30 @@ describe('match runtime with the simulator', () => {
await runtime.stop();
});
test('the due loop resumes a saved room even when all host slots are occupied', async () => {
const sim = new SimBancho(seeded(2));
const saved = await sim.open('Already created');
const initial = record(
{ bestOf: 1, teamSize: 1, scoringType: 'score_v2' },
slots(4, 0),
1,
true
);
initial.osuLobbyId = saved.id;
initial.ircAccount = saved.accountId;
const h = harness(initial, sim);
h.deps.dueMatchIds = async () => ['match-1'];
vi.spyOn(sim, 'capacity').mockReturnValue({ ...sim.capacity(), free: 0 });
const make = vi.spyOn(sim, 'open');
const runtime = new MatchRuntime(h.deps);
await runtime.boot();
await vi.advanceTimersByTimeAsync(1);
expect(h.stored().procedure.phase).toBe('waiting');
expect(h.stored().osuLobbyId).toBe(saved.id);
expect(make).not.toHaveBeenCalled();
await runtime.stop();
});
test('a reload waits for an in-flight make and reuses its persisted room', async () => {
const sim = new SimBancho(seeded(2));
const h = harness(

View File

@@ -1096,7 +1096,8 @@ export class MatchRuntime {
const ids = await this.deps.dueMatchIds().catch(() => []);
for (const id of ids) {
if (this.stopped) return;
if (this.deps.provider.capacity().free < 1) return;
// open() can reuse a saved room even when its host has no free slots.
// A new room checks capacity on this match's selected provider.
try {
await this.open(id);
this.openFailures.delete(id);