Skip to content

Commit 96dc506

Browse files
clydinKeen Yee Liau
authored and
Keen Yee Liau
committed
test(@angular-devkit/build-angular): expand polling success threshold
polling is highly dependent on CPU and IO; with shared CI machines this can cause high variability
1 parent b6ff520 commit 96dc506

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

packages/angular_devkit/build_angular/test/browser/poll_spec_large.ts

+13-14
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,26 @@ describe('Browser Builder poll', () => {
1616
afterEach(done => host.restore().toPromise().then(done, done.fail));
1717

1818
it('works', (done) => {
19-
const overrides = { watch: true, poll: 1000 };
20-
let msAvg = 1000;
21-
let lastTime: number;
19+
const overrides = { watch: true, poll: 2000 };
20+
const intervals: number[] = [];
21+
let startTime: number | undefined;
2222
runTargetSpec(host, browserTargetSpec, overrides).pipe(
2323
// Debounce 1s, otherwise changes are too close together and polling doesn't work.
2424
debounceTime(1000),
25-
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
26-
tap(() => {
27-
const currTime = Date.now();
28-
if (lastTime) {
29-
const ms = Math.floor((currTime - lastTime));
30-
msAvg = (msAvg + ms) / 2;
25+
tap((buildEvent) => {
26+
expect(buildEvent.success).toBe(true);
27+
if (startTime != undefined) {
28+
intervals.push(Date.now() - startTime - 1000);
3129
}
32-
lastTime = currTime;
30+
startTime = Date.now();
3331
host.appendToFile('src/main.ts', 'console.log(1);');
3432
}),
35-
take(5),
33+
take(6),
3634
).subscribe(undefined, done.fail, () => {
37-
// Check if the average is between 1750 and 2750, allowing for a 1000ms variance.
38-
expect(msAvg).toBeGreaterThan(1750);
39-
expect(msAvg).toBeLessThan(2750);
35+
intervals.sort();
36+
const median = intervals[Math.trunc(intervals.length / 2)];
37+
expect(median).toBeGreaterThan(1000);
38+
expect(median).toBeLessThan(4000);
4039
done();
4140
});
4241
});

0 commit comments

Comments
 (0)