-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: move execution of WPT to worker threads
Running outside of the main Node.js context prevents us from upgrading the WPT harness because new versions more aggressively check the identity of globals like error constructors. Instead of exposing globals used by the tests on vm sandboxes, use worker threads to run everything.
- Loading branch information
Showing
10 changed files
with
141 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* eslint-disable node-core/required-modules,node-core/require-common-first */ | ||
|
||
'use strict'; | ||
|
||
const { runInThisContext } = require('vm'); | ||
const { parentPort, workerData } = require('worker_threads'); | ||
|
||
const { ResourceLoader } = require(workerData.wptRunner); | ||
const resource = new ResourceLoader(workerData.wptPath); | ||
|
||
global.self = global; | ||
global.GLOBAL = { | ||
isWindow() { return false; } | ||
}; | ||
global.require = require; | ||
|
||
// This is a mock, because at the moment fetch is not implemented | ||
// in Node.js, but some tests and harness depend on this to pull | ||
// resources. | ||
global.fetch = function fetch(file) { | ||
return resource.read(workerData.filename, file, true); | ||
}; | ||
|
||
if (workerData.initScript) { | ||
runInThisContext(workerData.initScript); | ||
} | ||
|
||
runInThisContext(workerData.harness.code, { | ||
filename: workerData.harness.filename | ||
}); | ||
|
||
// eslint-disable-next-line no-undef | ||
add_result_callback((result) => { | ||
parentPort.postMessage({ | ||
type: 'result', | ||
result: { | ||
status: result.status, | ||
name: result.name, | ||
message: result.message, | ||
stack: result.stack, | ||
}, | ||
}); | ||
}); | ||
|
||
// eslint-disable-next-line no-undef | ||
add_completion_callback((_, status) => { | ||
parentPort.postMessage({ | ||
type: 'completion', | ||
status, | ||
}); | ||
}); | ||
|
||
for (const scriptToRun of workerData.scriptsToRun) { | ||
runInThisContext(scriptToRun.code, { filename: scriptToRun.filename }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,11 @@ | ||
'use strict'; | ||
require('../common'); | ||
const { MessageChannel } = require('worker_threads'); | ||
const { WPTRunner } = require('../common/wpt'); | ||
const runner = new WPTRunner('encoding'); | ||
|
||
// Copy global descriptors from the global object | ||
runner.copyGlobalsFromObject(global, ['TextDecoder', 'TextEncoder']); | ||
|
||
runner.defineGlobal('MessageChannel', { | ||
get() { | ||
return MessageChannel; | ||
} | ||
}); | ||
runner.setInitScript(` | ||
const { MessageChannel } = require('worker_threads'); | ||
global.MessageChannel = MessageChannel; | ||
`); | ||
|
||
runner.runJsTests(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,14 @@ | ||
'use strict'; | ||
|
||
// Flags: --expose-internals | ||
|
||
require('../common'); | ||
const { WPTRunner } = require('../common/wpt'); | ||
const { performance, PerformanceObserver } = require('perf_hooks'); | ||
|
||
const runner = new WPTRunner('hr-time'); | ||
|
||
runner.copyGlobalsFromObject(global, [ | ||
'setInterval', | ||
'clearInterval', | ||
'setTimeout', | ||
'clearTimeout' | ||
]); | ||
|
||
runner.defineGlobal('performance', { | ||
get() { | ||
return performance; | ||
} | ||
}); | ||
runner.defineGlobal('PerformanceObserver', { | ||
value: PerformanceObserver | ||
}); | ||
runner.setInitScript(` | ||
const { performance, PerformanceObserver } = require('perf_hooks'); | ||
global.performance = performance; | ||
global.PerformanceObserver = PerformanceObserver; | ||
`); | ||
|
||
runner.runJsTests(); |
Oops, something went wrong.