Skip to content

Commit 3ce086a

Browse files
devversionalan-agius4
authored andcommitted
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.
1 parent 2114f02 commit 3ce086a

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

packages/angular_devkit/architect/src/jobs/strategy_spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import { promisify } from 'util';
9+
import timers from 'node:timers/promises';
1010
import { JobState } from './api';
1111
import { createJobHandler } from './create-job-handler';
1212
import { SimpleJobRegistry } from './simple-registry';
1313
import { SimpleScheduler } from './simple-scheduler';
1414
import * as strategy from './strategy';
1515

16-
const flush = promisify(setImmediate);
16+
const flush = () => timers.setTimeout(1);
1717

1818
describe('strategy.serialize()', () => {
1919
let registry: SimpleJobRegistry;
@@ -37,7 +37,7 @@ describe('strategy.serialize()', () => {
3737
setTimeout(() => {
3838
finished++;
3939
resolve(input.reduce((a, c) => a + c, 0));
40-
}, 10),
40+
}, 100),
4141
);
4242
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4343
}) as any,
@@ -94,7 +94,7 @@ describe('strategy.serialize()', () => {
9494
setTimeout(() => {
9595
finished++;
9696
resolve(input.reduce((a, c) => a + c, 0));
97-
}, 10),
97+
}, 100),
9898
);
9999
// eslint-disable-next-line @typescript-eslint/no-explicit-any
100100
}) as any,
@@ -114,7 +114,7 @@ describe('strategy.serialize()', () => {
114114
setTimeout(() => {
115115
finished++;
116116
resolve(input.reduce((a, c) => a + c, 100));
117-
}, 10),
117+
}, 100),
118118
);
119119
// eslint-disable-next-line @typescript-eslint/no-explicit-any
120120
}) as any,
@@ -179,7 +179,7 @@ describe('strategy.reuse()', () => {
179179
setTimeout(() => {
180180
finished++;
181181
resolve(input.reduce((a, c) => a + c, 0));
182-
}, 10),
182+
}, 100),
183183
);
184184
// eslint-disable-next-line @typescript-eslint/no-explicit-any
185185
}) as any,
@@ -254,7 +254,7 @@ describe('strategy.memoize()', () => {
254254
setTimeout(() => {
255255
finished++;
256256
resolve(input.reduce((a, c) => a + c, 0));
257-
}, 10),
257+
}, 100),
258258
);
259259
// eslint-disable-next-line @typescript-eslint/no-explicit-any
260260
}) as any,

0 commit comments

Comments
 (0)