mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 11:24:58 +00:00
test: remove fixed delay from cron concurrency assertion
This commit is contained in:
@@ -824,6 +824,7 @@ describe("Cron issue regressions", () => {
|
|||||||
let now = dueAt;
|
let now = dueAt;
|
||||||
let activeRuns = 0;
|
let activeRuns = 0;
|
||||||
let peakActiveRuns = 0;
|
let peakActiveRuns = 0;
|
||||||
|
const bothRunsStarted = createDeferred<void>();
|
||||||
const firstRun = createDeferred<{ status: "ok"; summary: string }>();
|
const firstRun = createDeferred<{ status: "ok"; summary: string }>();
|
||||||
const secondRun = createDeferred<{ status: "ok"; summary: string }>();
|
const secondRun = createDeferred<{ status: "ok"; summary: string }>();
|
||||||
const state = createCronServiceState({
|
const state = createCronServiceState({
|
||||||
@@ -837,6 +838,9 @@ describe("Cron issue regressions", () => {
|
|||||||
runIsolatedAgentJob: vi.fn(async (params: { job: { id: string } }) => {
|
runIsolatedAgentJob: vi.fn(async (params: { job: { id: string } }) => {
|
||||||
activeRuns += 1;
|
activeRuns += 1;
|
||||||
peakActiveRuns = Math.max(peakActiveRuns, activeRuns);
|
peakActiveRuns = Math.max(peakActiveRuns, activeRuns);
|
||||||
|
if (peakActiveRuns >= 2) {
|
||||||
|
bothRunsStarted.resolve();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const result =
|
const result =
|
||||||
params.job.id === first.id ? await firstRun.promise : await secondRun.promise;
|
params.job.id === first.id ? await firstRun.promise : await secondRun.promise;
|
||||||
@@ -849,7 +853,12 @@ describe("Cron issue regressions", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const timerPromise = onTimer(state);
|
const timerPromise = onTimer(state);
|
||||||
await new Promise((resolve) => setTimeout(resolve, 20));
|
await Promise.race([
|
||||||
|
bothRunsStarted.promise,
|
||||||
|
new Promise<never>((_, reject) =>
|
||||||
|
setTimeout(() => reject(new Error("timed out waiting for concurrent job starts")), 1_000),
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
|
||||||
expect(peakActiveRuns).toBe(2);
|
expect(peakActiveRuns).toBe(2);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user