fix: refresh general turns at every execution boundary
This commit is contained in:
@@ -373,10 +373,12 @@ export class InMemoryReservedTurnStore {
|
|||||||
acquiredFreshNationLease = await this.acquireNationLease(nation.nationId, nation.officerLevel);
|
acquiredFreshNationLease = await this.acquireNationLease(nation.nationId, nation.officerLevel);
|
||||||
}
|
}
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
// A newly acquired lease starts a fresh API/daemon ownership boundary.
|
// A general queue is owned by only this execution. Once its lease
|
||||||
// Re-read PostgreSQL even if a prior run left a stale dirty marker;
|
// is held, PostgreSQL is authoritative even if an interrupted
|
||||||
// repeated access under the same held lease keeps local mutations.
|
// acknowledgement left stale dirty/lease markers in memory.
|
||||||
this.refreshGeneralTurns(generalId, acquiredFreshGeneralLease),
|
// Nation queues remain conditional because multiple officers can
|
||||||
|
// consume the same shared queue in one daemon batch.
|
||||||
|
this.refreshGeneralTurns(generalId, true),
|
||||||
nation
|
nation
|
||||||
? this.refreshNationTurns(nation.nationId, nation.officerLevel, acquiredFreshNationLease)
|
? this.refreshNationTurns(nation.nationId, nation.officerLevel, acquiredFreshNationLease)
|
||||||
: Promise.resolve(),
|
: Promise.resolve(),
|
||||||
|
|||||||
@@ -215,6 +215,20 @@ describe('reserved turn daemon lease', () => {
|
|||||||
expect(harness.generalFindMany).toHaveBeenCalledTimes(2);
|
expect(harness.generalFindMany).toHaveBeenCalledTimes(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('re-reads a general queue while retaining its execution lease', async () => {
|
||||||
|
const harness = buildHarness();
|
||||||
|
await harness.store.prepareTurnsForExecution(7);
|
||||||
|
harness.store.shiftGeneralTurns(7, -1);
|
||||||
|
|
||||||
|
expect(harness.getRevision()).toMatchObject({ leaseOwner: 'daemon-1' });
|
||||||
|
expect(harness.store.getGeneralTurn(7, 0).action).toBe('휴식');
|
||||||
|
|
||||||
|
await harness.store.prepareTurnsForExecution(7);
|
||||||
|
|
||||||
|
expect(harness.store.getGeneralTurn(7, 0).action).toBe('che_훈련');
|
||||||
|
expect(harness.generalFindMany).toHaveBeenCalledTimes(2);
|
||||||
|
});
|
||||||
|
|
||||||
it('rejects an active foreign lease before reading the queue', async () => {
|
it('rejects an active foreign lease before reading the queue', async () => {
|
||||||
const harness = buildHarness({
|
const harness = buildHarness({
|
||||||
revision: 4,
|
revision: 4,
|
||||||
|
|||||||
Reference in New Issue
Block a user