feat(companion): add manual heartbeat tick helper
This commit is contained in:
@@ -130,4 +130,14 @@ describe('CompanionHeartbeatLoop', () => {
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
expect(publishHeartbeat).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('tickNow sends heartbeat even when loop is not started', async () => {
|
||||
const publishHeartbeat = vi.fn(async () => buildStatusResult());
|
||||
const loop = new CompanionHeartbeatLoop({ publishHeartbeat }, { intervalMs: 1000 });
|
||||
|
||||
expect(loop.running).toBe(false);
|
||||
await loop.tickNow();
|
||||
expect(publishHeartbeat).toHaveBeenCalledTimes(1);
|
||||
expect(loop.running).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -65,6 +65,10 @@ export class CompanionHeartbeatLoop {
|
||||
}
|
||||
}
|
||||
|
||||
async tickNow(): Promise<void> {
|
||||
await this.tick(true);
|
||||
}
|
||||
|
||||
private scheduleNext(): void {
|
||||
if (!this.started) {
|
||||
return;
|
||||
@@ -74,8 +78,8 @@ export class CompanionHeartbeatLoop {
|
||||
}, this.intervalMs);
|
||||
}
|
||||
|
||||
private async tick(): Promise<void> {
|
||||
if (!this.started || this.inFlight) {
|
||||
private async tick(force = false): Promise<void> {
|
||||
if ((!this.started && !force) || this.inFlight) {
|
||||
return;
|
||||
}
|
||||
this.inFlight = true;
|
||||
|
||||
Reference in New Issue
Block a user