Skip to content

Commit

Permalink
test: improve stability of strategy tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
devversion authored and alan-agius4 committed Jan 20, 2025
1 parent 2114f02 commit 3ce086a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/angular_devkit/architect/src/jobs/strategy_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 3ce086a

Please sign in to comment.