Fix autoscaling lifecycle test timestamp race (Refs #79)
This commit is contained in:
@@ -5,7 +5,7 @@ import { zombieMaps } from '../../src/lib/map-aliases.js';
|
||||
|
||||
let fixture: Fixture;
|
||||
beforeEach(async () => { vi.resetModules(); fixture = await newFixture([]); });
|
||||
afterEach(async () => { await fixture.cleanup(); });
|
||||
afterEach(async () => { vi.useRealTimers(); await fixture.cleanup(); });
|
||||
const server = 't6_zombie_town_1';
|
||||
|
||||
async function setup(mapSlug: string) {
|
||||
@@ -45,6 +45,7 @@ it.each(['town', '*'])('keeps lineup-changing actions blocked for %s ownership',
|
||||
it.each([
|
||||
['town', 'restart'], ['town', 'rebuild'], ['*', 'restart'], ['*', 'rebuild']
|
||||
] as const)('allows %s-owned %s without scaling up during work or recovery', async (scope, action) => {
|
||||
vi.useFakeTimers({ toFake: ['Date'] });
|
||||
const { db, scaling, policy, requestLifecycle } = await setup(scope);
|
||||
const { scalingSnapshot } = await import('../../src/lib/server/autoscaling/snapshot.js');
|
||||
const result = requestLifecycle(server, action);
|
||||
@@ -63,13 +64,16 @@ it.each([
|
||||
|
||||
// A terminal operation with unresolved recovery must still hold capacity.
|
||||
db().prepare("UPDATE server_deployments SET state='failed' WHERE id=?").run(result.deploymentId);
|
||||
const requestedAt = new Date().toISOString();
|
||||
db().prepare('INSERT INTO restart_rollout(server,requested_at,operation_id) VALUES(?,?,?)')
|
||||
.run(server, new Date().toISOString(), result.deploymentId);
|
||||
.run(server, requestedAt, result.deploymentId);
|
||||
expect(scalingSnapshot(policy).members.find(member => member.name === server)?.blocker).toBe('Unresolved recovery');
|
||||
expect(await scaling.runAutoscaling()).toBe(false);
|
||||
expect(db().prepare("SELECT id FROM server_deployments WHERE action IN ('create','destroy')").all()).toEqual([]);
|
||||
|
||||
const at = new Date().toISOString();
|
||||
// Recovery status must be strictly newer than the restart request.
|
||||
const at = new Date(Date.parse(requestedAt) + 1_000).toISOString();
|
||||
vi.setSystemTime(new Date(at));
|
||||
db().prepare("UPDATE server_deployments SET state='done',finished_at=? WHERE id=?").run(at, result.deploymentId);
|
||||
db().prepare('UPDATE restart_rollout SET healthy_at=? WHERE server=?').run(at, server);
|
||||
db().prepare("UPDATE servers SET container_state='running',last_players=0,container_checked_at=?,last_seen_at=?,last_checked_at=?")
|
||||
|
||||
Reference in New Issue
Block a user