Skip to content

Commit f8e3df1

Browse files
authored
Stop runner from hanging indefinitely within ubuntu docker images [elastic/beats#29681] (#441)
* fix: stop runner from hanging indefinitely within ubuntu docker images [elastic/beats#29681] * fix: enable --disable-gpu flag only for headless runs
1 parent df88c62 commit f8e3df1

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

__tests__/core/gatherer.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { wsEndpoint } from '../utils/test-config';
2929
import { devices } from 'playwright-chromium';
3030
import { Server } from '../utils/server';
3131
import { megabitsToBytes } from '../../src/helpers';
32+
import { chromium } from 'playwright-chromium';
3233

3334
jest.mock('../../src/plugins/network');
3435

@@ -42,12 +43,60 @@ describe('Gatherer', () => {
4243
await server.close();
4344
});
4445

46+
afterEach(() => {
47+
jest.restoreAllMocks();
48+
});
49+
4550
it('boot and close browser', async () => {
4651
const driver = await Gatherer.setupDriver({ wsEndpoint });
4752
expect(typeof driver.page.goto).toBe('function');
4853
await Gatherer.stop();
4954
});
5055

56+
// This test should only run when a browser service is up
57+
(wsEndpoint ? it : it.skip)(
58+
'does not the disable-gpu flag to start browser when running headful',
59+
async () => {
60+
const chromiumLaunch = jest
61+
.spyOn(chromium, 'launch')
62+
.mockImplementation(() => {
63+
return chromium.connect({ wsEndpoint });
64+
});
65+
66+
await Gatherer.setupDriver({
67+
playwrightOptions: { headless: false },
68+
});
69+
expect(chromiumLaunch).toHaveBeenCalledWith(
70+
expect.objectContaining({
71+
args: expect.not.arrayContaining(['--disable-gpu']),
72+
})
73+
);
74+
await Gatherer.stop();
75+
}
76+
);
77+
78+
// This test should only run when a browser service is up
79+
(wsEndpoint ? it : it.skip)(
80+
'uses the disable-gpu flag to start browser when running headlessly',
81+
async () => {
82+
const chromiumLaunch = jest
83+
.spyOn(chromium, 'launch')
84+
.mockImplementation(() => {
85+
return chromium.connect({ wsEndpoint });
86+
});
87+
88+
await Gatherer.setupDriver({
89+
playwrightOptions: { headless: true },
90+
});
91+
expect(chromiumLaunch).toHaveBeenCalledWith(
92+
expect.objectContaining({
93+
args: expect.arrayContaining(['--disable-gpu']),
94+
})
95+
);
96+
await Gatherer.stop();
97+
}
98+
);
99+
51100
it('setup and dispose driver', async () => {
52101
const driver = await Gatherer.setupDriver({ wsEndpoint });
53102
await Gatherer.dispose(driver);

src/core/gatherer.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ export class Gatherer {
4545
log(`Gatherer: connecting to WS endpoint: ${wsEndpoint}`);
4646
Gatherer.browser = await chromium.connect({ wsEndpoint });
4747
} else {
48-
Gatherer.browser = await chromium.launch(playwrightOptions);
48+
Gatherer.browser = await chromium.launch({
49+
...playwrightOptions,
50+
args: [
51+
...(playwrightOptions?.headless ? ['--disable-gpu'] : []),
52+
...(playwrightOptions?.args ?? []),
53+
],
54+
});
4955
}
5056
}
5157
const context = await Gatherer.browser.newContext({

0 commit comments

Comments
 (0)