ai-chatbot/tests/routes/canvas-image-queue-fairness.test.ts

60 lines
1.4 KiB
TypeScript

import { expect, test } from "@playwright/test";
import {
estimateImageDispatchWaitMs,
getAdaptiveImageQueueOwnerLimit,
} from "@/lib/canvas/image-queue-fairness";
test.describe("canvas image queue fairness", () => {
test("lets one owner use the full model capacity without competition", () => {
expect(
getAdaptiveImageQueueOwnerLimit({
maxConcurrent: 10,
hasCompetingOwner: false,
})
).toBe(10);
});
test("reserves half the slots when another owner is waiting", () => {
expect(
getAdaptiveImageQueueOwnerLimit({
maxConcurrent: 10,
hasCompetingOwner: true,
})
).toBe(5);
expect(
getAdaptiveImageQueueOwnerLimit({
maxConcurrent: 5,
hasCompetingOwner: true,
})
).toBe(3);
});
test("always keeps at least one executable slot", () => {
expect(
getAdaptiveImageQueueOwnerLimit({
maxConcurrent: 0,
hasCompetingOwner: true,
})
).toBe(1);
});
test("estimates queue wait from request dispatch spacing, not generation duration", () => {
expect(
estimateImageDispatchWaitMs({
queuePosition: 3,
dispatchIntervalMs: 1000,
delayRemainingMs: 400,
})
).toBe(3400);
});
test("does not add wait after the request has no tasks ahead", () => {
expect(
estimateImageDispatchWaitMs({
queuePosition: 0,
dispatchIntervalMs: 1000,
})
).toBe(0);
});
});