From 6012b50d8919d8be7f2dc9a335db0399acd65cd8 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Fri, 25 Oct 2024 11:32:00 -0400 Subject: [PATCH] test: deflake flaky tests on linux (#44401) Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt --- spec/api-browser-window-spec.ts | 5 ++--- spec/crash-spec.ts | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/spec/api-browser-window-spec.ts b/spec/api-browser-window-spec.ts index 15c36e707acd..74affcf5bd1b 100755 --- a/spec/api-browser-window-spec.ts +++ b/spec/api-browser-window-spec.ts @@ -942,12 +942,11 @@ describe('BrowserWindow module', () => { 'did-frame-navigate', 'did-navigate' ]; - const allEvents = Promise.all(navigationEvents.map(event => + const allEvents = Promise.all(expectedEventOrder.map(event => once(w.webContents, event).then(() => firedEvents.push(event)) )); - const timeout = setTimeout(1000); w.loadURL(url); - await Promise.race([allEvents, timeout]); + await allEvents; expect(firedEvents).to.deep.equal(expectedEventOrder); }); diff --git a/spec/crash-spec.ts b/spec/crash-spec.ts index ff8489b050d1..253537b43b1e 100644 --- a/spec/crash-spec.ts +++ b/spec/crash-spec.ts @@ -4,7 +4,7 @@ import * as cp from 'node:child_process'; import * as fs from 'node:fs'; import * as path from 'node:path'; -import { ifit } from './lib/spec-helpers'; +import { ifit, waitUntil } from './lib/spec-helpers'; const fixturePath = path.resolve(__dirname, 'fixtures', 'crash-cases'); @@ -57,11 +57,11 @@ const shouldRunCase = (crashCase: string) => { }; describe('crash cases', () => { - afterEach(() => { + afterEach(async () => { for (const child of children) { child.kill(); } - expect(children).to.have.lengthOf(0, 'all child processes should have exited cleanly'); + await waitUntil(() => (children.length === 0)); children.length = 0; }); const cases = fs.readdirSync(fixturePath);