From 3ce086a5c87884a5a284da80b1cda5c5c129fbe3 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Fri, 17 Jan 2025 13:05:08 +0000 Subject: [PATCH] test: improve stability of strategy tests The strategy tests are extremely time-sensitive with regards to the RxJS job logic executing, and the tests currently rely on `setImmediate` to flush/trigger job execution. This seems to be rather unstable via Remote execution, and sensitive to changes with the execution (e.g. injecting source map support or not), so we are stabilizing the tests further by having better time delays for job execution, and by using `setTimeout` for flushing. This seems very sufficient. --- .../architect/src/jobs/strategy_spec.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/angular_devkit/architect/src/jobs/strategy_spec.ts b/packages/angular_devkit/architect/src/jobs/strategy_spec.ts index 4f6ae44b60c1..c73d5dcd8b4a 100644 --- a/packages/angular_devkit/architect/src/jobs/strategy_spec.ts +++ b/packages/angular_devkit/architect/src/jobs/strategy_spec.ts @@ -6,14 +6,14 @@ * found in the LICENSE file at https://angular.dev/license */ -import { promisify } from 'util'; +import timers from 'node:timers/promises'; import { JobState } from './api'; import { createJobHandler } from './create-job-handler'; import { SimpleJobRegistry } from './simple-registry'; import { SimpleScheduler } from './simple-scheduler'; import * as strategy from './strategy'; -const flush = promisify(setImmediate); +const flush = () => timers.setTimeout(1); describe('strategy.serialize()', () => { let registry: SimpleJobRegistry; @@ -37,7 +37,7 @@ describe('strategy.serialize()', () => { setTimeout(() => { finished++; resolve(input.reduce((a, c) => a + c, 0)); - }, 10), + }, 100), ); // eslint-disable-next-line @typescript-eslint/no-explicit-any }) as any, @@ -94,7 +94,7 @@ describe('strategy.serialize()', () => { setTimeout(() => { finished++; resolve(input.reduce((a, c) => a + c, 0)); - }, 10), + }, 100), ); // eslint-disable-next-line @typescript-eslint/no-explicit-any }) as any, @@ -114,7 +114,7 @@ describe('strategy.serialize()', () => { setTimeout(() => { finished++; resolve(input.reduce((a, c) => a + c, 100)); - }, 10), + }, 100), ); // eslint-disable-next-line @typescript-eslint/no-explicit-any }) as any, @@ -179,7 +179,7 @@ describe('strategy.reuse()', () => { setTimeout(() => { finished++; resolve(input.reduce((a, c) => a + c, 0)); - }, 10), + }, 100), ); // eslint-disable-next-line @typescript-eslint/no-explicit-any }) as any, @@ -254,7 +254,7 @@ describe('strategy.memoize()', () => { setTimeout(() => { finished++; resolve(input.reduce((a, c) => a + c, 0)); - }, 10), + }, 100), ); // eslint-disable-next-line @typescript-eslint/no-explicit-any }) as any,