mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
src/next is src (the main export), src/next-node is src/node with short subpaths (/http, /workers, /plugins, /plugins/runtime, /app, /surfaces, /web, /react, /tui, /tui/launcher); the foundations get /json and /watch; Chord v1 moves to src/old (/old, /old/node) until p2 runs on v2; tests and docs move likewise (test/, docs/, test/old, docs/old). Durable and env import the foundations from their subpaths.
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
// Tests of an activation's deadline (slice 6a §9): it expires once after its budget; paused time does not count; a
|
|
// cleared deadline never expires.
|
|
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { Deadline } from "../../src/host/deadline.ts";
|
|
import { fakeTimers } from "../support.ts";
|
|
|
|
describe("deadline", () => {
|
|
fakeTimers();
|
|
|
|
it("expires once after its budget", () => {
|
|
const expired = vi.fn();
|
|
new Deadline(100, expired);
|
|
vi.advanceTimersByTime(99);
|
|
expect(expired).not.toHaveBeenCalled();
|
|
vi.advanceTimersByTime(1_000);
|
|
expect(expired).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("paused time does not count: resumed with the budget it had left", () => {
|
|
const expired = vi.fn();
|
|
const deadline = new Deadline(100, expired);
|
|
vi.advanceTimersByTime(60);
|
|
deadline.pause();
|
|
vi.advanceTimersByTime(1_000);
|
|
deadline.resume();
|
|
vi.advanceTimersByTime(39);
|
|
expect(expired).not.toHaveBeenCalled();
|
|
vi.advanceTimersByTime(1);
|
|
expect(expired).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("a cleared deadline never expires, also when resumed", () => {
|
|
const expired = vi.fn();
|
|
const deadline = new Deadline(100, expired);
|
|
deadline.pause();
|
|
deadline.clear();
|
|
deadline.resume();
|
|
vi.advanceTimersByTime(1_000);
|
|
expect(expired).not.toHaveBeenCalled();
|
|
});
|
|
});
|