mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-10 02:15:02 +00:00
fix(server): pick the git job when its start token fires
Background jobs that already reserved a start-rate token no longer start ahead of normal work submitted after them.
This commit is contained in:
@@ -94,6 +94,38 @@ describe("GitProcessScheduler", () => {
|
||||
expect(started).toEqual([0, 6, 5, 2, 3, 4]);
|
||||
});
|
||||
|
||||
test("starts normal work at the next start slot when background work saturates the rate", async () => {
|
||||
vi.useFakeTimers();
|
||||
const scheduler = new GitProcessScheduler({
|
||||
maxProcessesPerSecond: 2,
|
||||
maxProcessConcurrency: 8,
|
||||
});
|
||||
const started: string[] = [];
|
||||
const task = (name: string) => () => {
|
||||
started.push(name);
|
||||
const completed = Promise.resolve();
|
||||
return { result: completed, exited: completed };
|
||||
};
|
||||
const background = Array.from({ length: 8 }, (_, index) =>
|
||||
scheduler.run(task(`background-${index}`), { priority: "background" }),
|
||||
);
|
||||
// Admission yields a real event-loop turn per process; let every
|
||||
// background job reach the start-rate limiter.
|
||||
for (let turn = 0; turn < 10; turn += 1) {
|
||||
await new Promise<void>((resolve) => scheduleImmediate(resolve));
|
||||
}
|
||||
expect(started).toEqual(["background-0", "background-1"]);
|
||||
|
||||
const normal = scheduler.run(task("normal"));
|
||||
while (started.length < 3) {
|
||||
await vi.advanceTimersToNextTimerAsync();
|
||||
}
|
||||
|
||||
expect(started[2]).toBe("normal");
|
||||
await vi.runAllTimersAsync();
|
||||
await Promise.all([...background, normal]);
|
||||
});
|
||||
|
||||
test("yields to daemon liveness work between process starts", async () => {
|
||||
const scheduler = new GitProcessScheduler({
|
||||
maxProcessesPerSecond: 100,
|
||||
|
||||
Reference in New Issue
Block a user