fix(workers): workaround worker execution context flakiness (#2596)

Some of the worker tests were failing on the bots. After investigating, I found one race in the test, and one race upstream in Chromium which I filed upstream as https://crbug.com/846099. But I added a small hack here as a temporary workaround.

References #2632
This commit is contained in:
Joel Einbinder 2018-05-30 18:08:27 -07:00 committed by Andrey Lushnikov
parent 469b910a2d
commit 1c2adf61e9
2 changed files with 10 additions and 3 deletions

View File

@ -28,7 +28,13 @@ class Worker extends EventEmitter {
this._client = client;
this._url = url;
this._executionContextPromise = new Promise(x => this._executionContextCallback = x);
this._client.on('Runtime.executionContextCreated', event => {
this._client.once('Runtime.executionContextCreated', async event => {
// Get a reference to the main object on the worker as a hack around https://crbug.com/846099.
await this._client.send('Runtime.evaluate', {
expression: 'this',
returnByValue: false,
contextId: event.executionContextId
}).catch(debugError);
const jsHandleFactory = remoteObject => new JSHandle(executionContext, client, remoteObject);
const executionContext = new ExecutionContext(client, event.context, jsHandleFactory, null);
this._executionContextCallback(executionContext);

View File

@ -1627,8 +1627,9 @@ module.exports.addTests = function({testRunner, expect, puppeteer, DeviceDescrip
});
describe('Workers', function() {
it('Page.workers', async function({page, server}) {
await page.goto(server.PREFIX + '/worker/worker.html');
await page.waitForFunction(() => !!worker);
await Promise.all([
new Promise(x => page.once('workercreated', x)),
page.goto(server.PREFIX + '/worker/worker.html')]);
const worker = page.workers()[0];
expect(worker.url()).toContain('worker.js');
const executionContext = await worker.executionContext();