feat(companion): add manual heartbeat tick helper

This commit is contained in:
William Valentin
2026-02-16 18:46:48 -08:00
parent 985b7bf459
commit 873dc1ad5b
4 changed files with 30 additions and 3 deletions
+10
View File
@@ -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);
});
});
+6 -2
View File
@@ -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;