Skip to content

Commit

Permalink
test(wpt): implement process timeout, fix expectations update, and mo…
Browse files Browse the repository at this point in the history
…re... (denoland#17892)

- relands denoland#17872
- updates the timeouts to be re-configurable just for CI
- fixes `./tools/wpt.ts update`
- adds option not "ignore" during, applied to wpt epoch runs only
  • Loading branch information
panva committed Mar 2, 2023
1 parent 88c9a99 commit 64503fa
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/wpt_epoch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
deno run --unstable --allow-write --allow-read --allow-net \
--allow-env --allow-run --lock=tools/deno.lock.json \
./tools/wpt.ts run \
--binary=$(which deno) --quiet --release --json=wpt.json --wptreport=wptreport.json || true
--binary=$(which deno) --quiet --release --no-ignore --json=wpt.json --wptreport=wptreport.json || true
- name: Upload wpt results to wpt.fyi
env:
Expand Down
9 changes: 7 additions & 2 deletions tools/wpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
ManifestFolder,
ManifestTestOptions,
ManifestTestVariation,
noIgnore,
quiet,
rest,
runPy,
Expand Down Expand Up @@ -173,6 +174,9 @@ async function run() {
test.options,
inParallel ? () => {} : createReportTestCase(test.expectation),
inspectBrk,
Deno.env.get("CI")
? { long: 4 * 60_000, default: 4 * 60_000 }
: { long: 60_000, default: 10_000 },
);
results.push({ test, result });
if (inParallel) {
Expand Down Expand Up @@ -332,6 +336,7 @@ async function update() {
test.options,
json ? () => {} : createReportTestCase(test.expectation),
inspectBrk,
{ long: 60_000, default: 10_000 },
);
results.push({ test, result });
reportVariation(result, test.expectation);
Expand Down Expand Up @@ -367,7 +372,7 @@ async function update() {

const currentExpectation = getExpectation();

for (const result of Object.values(resultTests)) {
for (const [path, result] of Object.entries(resultTests)) {
const { passed, failed, testSucceeded } = result;
let finalExpectation: boolean | string[];
if (failed.length == 0 && testSucceeded) {
Expand Down Expand Up @@ -699,7 +704,7 @@ function discoverTestsToRun(
typeof expectation.ignore === "boolean",
"test entry's `ignore` key must be a boolean",
);
if (expectation.ignore === true) continue;
if (expectation.ignore === true && !noIgnore) continue;
}
}

Expand Down
4 changes: 2 additions & 2 deletions tools/wpt/expectation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1087,8 +1087,8 @@
"EventTarget-constructible.any.html": true,
"EventTarget-constructible.any.worker.html": true,
"Event-constructors.any.html": [
"Untitled 3",
"Untitled 4"
"Event constructors 3",
"Event constructors 4"
],
"Event-constructors.any.worker.html": [
"Event constructors 3",
Expand Down
21 changes: 21 additions & 0 deletions tools/wpt/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,23 @@ export async function runSingleTest(
_options: ManifestTestOptions,
reporter: (result: TestCaseResult) => void,
inspectBrk: boolean,
timeouts: { long: number; default: number },
): Promise<TestResult> {
const timeout = _options.timeout === "long"
? timeouts.long
: timeouts.default;
const filename = url.pathname.substring(
url.pathname.lastIndexOf("/") + 1,
url.pathname.indexOf("."),
);
const { title } = Object.fromEntries(_options.script_metadata || []);
const bundle = await generateBundle(url);
const tempFile = await Deno.makeTempFile({
prefix: "wpt-bundle-",
suffix: ".js",
});

let interval;
try {
await Deno.writeTextFile(tempFile, bundle);

Expand All @@ -107,6 +117,7 @@ export async function runSingleTest(
"[]",
);

const start = performance.now();
const proc = new Deno.Command(denoBinary(), {
args,
env: {
Expand All @@ -124,10 +135,19 @@ export async function runSingleTest(
const lines = proc.stderr.pipeThrough(new TextDecoderStream()).pipeThrough(
new TextLineStream(),
);
interval = setInterval(() => {
const passedTime = performance.now() - start;
if (passedTime > timeout) {
proc.kill("SIGINT");
}
}, 1000);
for await (const line of lines) {
if (line.startsWith("{")) {
const data = JSON.parse(line);
const result = { ...data, passed: data.status == 0 };
if (/^Untitled( \d+)?$/.test(result.name)) {
result.name = `${title || filename}${result.name.slice(8)}`;
}
cases.push(result);
reporter(result);
} else if (line.startsWith("#$#$#{")) {
Expand All @@ -149,6 +169,7 @@ export async function runSingleTest(
stderr,
};
} finally {
clearInterval(interval);
await Deno.remove(tempFile);
}
}
Expand Down
3 changes: 2 additions & 1 deletion tools/wpt/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ export const {
["--"]: rest,
["auto-config"]: autoConfig,
["inspect-brk"]: inspectBrk,
["no-ignore"]: noIgnore,
binary,
} = parse(Deno.args, {
"--": true,
boolean: ["quiet", "release", "no-interactive", "inspect-brk"],
boolean: ["quiet", "release", "no-interactive", "inspect-brk", "no-ignore"],
string: ["json", "wptreport", "binary"],
});

Expand Down

0 comments on commit 64503fa

Please sign in to comment.