Skip to content

Commit

Permalink
wpt: run tests in parallel (2.5x speed improvement) (#1714)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev authored Oct 18, 2022
1 parent 145358d commit 7102eb0
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions test/wpt/runner/runner/runner.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventEmitter, once } from 'node:events'
import { EventEmitter } from 'node:events'
import { readdirSync, readFileSync, statSync } from 'node:fs'
import { basename, isAbsolute, join, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
Expand Down Expand Up @@ -77,8 +77,10 @@ export class WPTRunner extends EventEmitter {
return [...files]
}

async run () {
run () {
const workerPath = fileURLToPath(join(import.meta.url, '../worker.mjs'))
/** @type {Set<Worker>} */
const activeWorkers = new Set()

for (const test of this.#files) {
const code = test.includes('.sub.')
Expand All @@ -99,6 +101,8 @@ export class WPTRunner extends EventEmitter {
}
})

activeWorkers.add(worker)

worker.on('message', (message) => {
if (message.type === 'result') {
this.handleIndividualTestCompletion(message, basename(test))
Expand All @@ -107,17 +111,14 @@ export class WPTRunner extends EventEmitter {
}
})

await once(worker, 'exit')
}
worker.once('exit', () => {
activeWorkers.delete(worker)

this.emit('completion')
const { completed, failed, success, expectedFailures } = this.#stats
console.log(
`[${this.#folderName}]: ` +
`Completed: ${completed}, failed: ${failed}, success: ${success}, ` +
`expected failures: ${expectedFailures}, ` +
`unexpected failures: ${failed - expectedFailures}`
)
if (activeWorkers.size === 0) {
this.handleRunnerCompletion()
}
})
}
}

/**
Expand Down Expand Up @@ -156,6 +157,20 @@ export class WPTRunner extends EventEmitter {
worker.terminate()
}

/**
* Called after every test has completed.
*/
handleRunnerCompletion () {
this.emit('completion')
const { completed, failed, success, expectedFailures } = this.#stats
console.log(
`[${this.#folderName}]: ` +
`Completed: ${completed}, failed: ${failed}, success: ${success}, ` +
`expected failures: ${expectedFailures}, ` +
`unexpected failures: ${failed - expectedFailures}`
)
}

addInitScript (code) {
this.#initScripts.push(code)
}
Expand Down

0 comments on commit 7102eb0

Please sign in to comment.