|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { isQueueAtCapacity, isQueueDegraded, OLDEST_WAIT_WARNING_MS } from "./queue-thresholds"; |
| 3 | + |
| 4 | +describe("isQueueAtCapacity", () => { |
| 5 | + it("is false for a zero limit with a backlog", () => { |
| 6 | + expect(isQueueAtCapacity({ running: 0, queued: 12, limit: 0 })).toBe(false); |
| 7 | + expect(isQueueAtCapacity({ running: 3, queued: 12, limit: 0 })).toBe(false); |
| 8 | + }); |
| 9 | + |
| 10 | + it("is false when no limit is known", () => { |
| 11 | + expect(isQueueAtCapacity({ running: 5, queued: 12, limit: null })).toBe(false); |
| 12 | + expect(isQueueAtCapacity({ running: 5, queued: 12, limit: undefined })).toBe(false); |
| 13 | + }); |
| 14 | + |
| 15 | + it("is true when a positive limit is full and work is waiting", () => { |
| 16 | + expect(isQueueAtCapacity({ running: 10, queued: 4, limit: 10 })).toBe(true); |
| 17 | + expect(isQueueAtCapacity({ running: 11, queued: 1, limit: 10 })).toBe(true); |
| 18 | + }); |
| 19 | + |
| 20 | + it("is false when the limit is full but nothing is waiting", () => { |
| 21 | + expect(isQueueAtCapacity({ running: 10, queued: 0, limit: 10 })).toBe(false); |
| 22 | + }); |
| 23 | +}); |
| 24 | + |
| 25 | +describe("isQueueDegraded", () => { |
| 26 | + const base = { paused: false, oldestWaitMs: null }; |
| 27 | + |
| 28 | + it("does not degrade a zero-limit queue with a backlog", () => { |
| 29 | + expect(isQueueDegraded({ ...base, running: 0, queued: 12, limit: 0 })).toBe(false); |
| 30 | + }); |
| 31 | + |
| 32 | + it("degrades a saturated queue", () => { |
| 33 | + expect(isQueueDegraded({ ...base, running: 10, queued: 4, limit: 10 })).toBe(true); |
| 34 | + }); |
| 35 | + |
| 36 | + it("degrades on head-of-line wait regardless of the limit", () => { |
| 37 | + expect( |
| 38 | + isQueueDegraded({ |
| 39 | + paused: false, |
| 40 | + running: 0, |
| 41 | + queued: 12, |
| 42 | + limit: 0, |
| 43 | + oldestWaitMs: OLDEST_WAIT_WARNING_MS, |
| 44 | + }) |
| 45 | + ).toBe(true); |
| 46 | + }); |
| 47 | + |
| 48 | + it("never degrades a paused queue", () => { |
| 49 | + expect( |
| 50 | + isQueueDegraded({ |
| 51 | + paused: true, |
| 52 | + running: 10, |
| 53 | + queued: 4, |
| 54 | + limit: 10, |
| 55 | + oldestWaitMs: OLDEST_WAIT_WARNING_MS * 10, |
| 56 | + }) |
| 57 | + ).toBe(false); |
| 58 | + }); |
| 59 | +}); |
0 commit comments