client/packages/mtp/src/requestIds.test.ts
Alex 2a55c87df1
Some checks failed
Dependency builds / Build web (pull_request) Has been skipped
Dependency builds / Build desktop (pull_request) Has been skipped
Dependency builds / Test native MTP (pull_request) Has been skipped
Dependency builds / Build mobile (pull_request) Has been skipped
/ build-web (push) Failing after 3m32s
/ build-desktop (linux) (push) Failing after 2m47s
/ build-mobile (push) Failing after 5m29s
/ release (push) Has been skipped
[Updt] Mtp 0.3.0
2026-08-20 17:05:53 +02:00

25 lines
743 B
TypeScript

import { describe, expect, it } from "vitest";
import { RequestIdAllocator } from "./requestIds";
describe("MTP request ID allocation", () => {
it("allocates nonzero request IDs monotonically", () => {
const ids = new RequestIdAllocator();
expect(ids.allocate()).toBe(1);
expect(ids.allocate()).toBe(2);
expect(new RequestIdAllocator().allocate()).toBe(1);
});
it("does not wrap exhausted request IDs", () => {
const ids = new RequestIdAllocator(0x1_0000_0000);
expect(() => ids.allocate()).toThrow("MTP request ID space exhausted");
});
it("rejects invalid allocator states", () => {
expect(() => new RequestIdAllocator(0)).toThrow(
"invalid MTP request ID allocator state",
);
});
});