Release agent@1.1.1: stats during jobs, its real version
Stats go every minute on their own timer, also while a job runs (before, a 30-minute install made the Hub alert that the server was down). The version constant said 1.0.1 in 1.1.0; a test keeps it equal to package.json now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -42,6 +42,32 @@ function make(jobs: unknown[], run: jest.Mock<ReturnType<Run>, Parameters<Run>>
|
||||
const reports = (posts: { path: string; body: unknown }[]) => posts.filter((p) => p.path === "/api/agent/v1/report").map((p) => p.body as agent.AgentReport);
|
||||
|
||||
describe("the agent loop", () => {
|
||||
it("keeps sending stats while a long job runs, so the Hub doesn't think it's down", async () => {
|
||||
jest.useFakeTimers();
|
||||
try {
|
||||
let finish!: () => void;
|
||||
const longRun = jest.fn<ReturnType<Run>, Parameters<Run>>(() => new Promise<RunResult>((resolve) => { finish = () => resolve(ok()); }));
|
||||
const h = fakeHub([job()]);
|
||||
const a = new Agent({ config, keys: { ed25519Pem: serverKeys.ed25519.privateKeyPem, x25519Pem: serverKeys.x25519.privateKeyPem }, hub: h.hub, seen: new SeenJobs(path.join(state, `seen-${Math.random()}.json`)), run: longRun, now: () => NOW, stats: async () => ({}) as agent.AgentStats });
|
||||
const running = a.start();
|
||||
await jest.advanceTimersByTimeAsync(10);
|
||||
expect(longRun).toHaveBeenCalledTimes(1);
|
||||
// 20 minutes of a job: a stats post every minute all the way through.
|
||||
await jest.advanceTimersByTimeAsync(20 * 60 * 1000);
|
||||
const stats = h.posts.filter((p) => p.path === "/api/agent/v1/stats").length;
|
||||
expect(stats).toBeGreaterThanOrEqual(20);
|
||||
expect(reports(h.posts)).toHaveLength(0);
|
||||
finish();
|
||||
await jest.advanceTimersByTimeAsync(10);
|
||||
expect(reports(h.posts)).toHaveLength(1);
|
||||
a.stop();
|
||||
await jest.advanceTimersByTimeAsync(60 * 1000);
|
||||
await running;
|
||||
} finally {
|
||||
jest.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
it("runs a valid job once and reports it", async () => {
|
||||
const j = job();
|
||||
const { a, run, posts } = make([j, j]);
|
||||
|
||||
Reference in New Issue
Block a user