Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: enable wpt for url #9046

Merged
merged 19 commits into from
Jan 24, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@ jobs:
echo $(git rev-parse HEAD) > canary-latest.txt
gsutil cp canary-latest.txt gs://dl.deno.land/canary-latest.txt

- name: Configure hosts file for WPT (unix)
if: runner.os != 'Windows'
run: ./wpt make-hosts-file | sudo tee -a /etc/hosts
working-directory: test_util/wpt/

- name: Configure hosts file for WPT (windows)
if: runner.os == 'Windows'
working-directory: test_util/wpt/
run: python wpt make-hosts-file | Out-File $env:SystemRoot\System32\drivers\etc\hosts -Encoding ascii -Append

lucacasonato marked this conversation as resolved.
Show resolved Hide resolved
- name: Test release
if: matrix.kind == 'test_release'
run: cargo test --release --locked --all-targets
Expand Down
98 changes: 95 additions & 3 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use deno_core::serde_json;
use deno_core::url;
use deno_runtime::deno_fetch::reqwest;
use deno_runtime::deno_websocket::tokio_tungstenite;
use std::io::BufReader;
use std::io::{BufRead, Write};
use std::path::Path;
use std::path::PathBuf;
Expand Down Expand Up @@ -5236,6 +5237,32 @@ fn jsonc_to_serde(j: jsonc_parser::JsonValue) -> serde_json::Value {
}
}

struct WPTServer(std::process::Child);

impl Drop for WPTServer {
fn drop(&mut self) {
match self.0.try_wait() {
Ok(None) => {
#[cfg(target_os = "linux")]
{
println!("libc kill");
unsafe {
libc::kill(self.0.id() as i32, libc::SIGTERM);
}
}
#[cfg(not(target_os = "linux"))]
{
println!("std kill");
self.0.kill().expect("killing 'wpt serve' failed");
}
let _ = self.0.wait();
}
Ok(Some(status)) => panic!("'wpt serve' exited unexpectedly {}", status),
Err(e) => panic!("'wpt serve' error: {}", e),
}
}
}

#[test]
fn web_platform_tests() {
use deno_core::serde::Deserialize;
Expand All @@ -5257,6 +5284,62 @@ fn web_platform_tests() {
let config: std::collections::HashMap<String, Vec<WptConfig>> =
deno_core::serde_json::from_value(jsonc_to_serde(jsonc)).unwrap();

// The windows-2019 buildbots are too slow to finish the WPT tests within
// the 1 hour time limit.
if cfg!(target_os = "windows") && std::env::var("CI").is_ok() {
return;
}

// Observation: `python3 wpt serve` hangs with the python3 from homebrew
// but works okay with /usr/bin/python, which is python 2.7.10. Observed
// with homebrew python 3.8.5, 3.8.7 and 3.9.1.
let python = match true {
_ if cfg!(target_os = "windows") => "python.exe",
_ if cfg!(target_os = "macos") => "python",
_ => "python3",
};

let mut proc = Command::new(python)
.current_dir(util::wpt_path())
.arg("wpt")
.arg("serve")
.stderr(std::process::Stdio::piped())
.spawn()
.unwrap();

let stderr = proc.stderr.as_mut().unwrap();
let mut stderr = BufReader::new(stderr).lines();
let mut ready_8000 = false;
let mut ready_8443 = false;
let mut ready_8444 = false;
let mut ready_9000 = false;
while let Ok(line) = stderr.next().unwrap() {
if !line.starts_with("DEBUG:") {
eprintln!("{}", line);
}
if line.contains("web-platform.test:8000") {
ready_8000 = true;
}
if line.contains("web-platform.test:8443") {
ready_8443 = true;
}
if line.contains("web-platform.test:8444") {
ready_8444 = true;
}
if line.contains("web-platform.test:9000") {
ready_9000 = true;
}
// WPT + python2 doesn't support HTTP/2.0.
if line.contains("Cannot start HTTP/2.0 server") {
ready_9000 = true;
}
if ready_8000 && ready_8443 && ready_8444 && ready_9000 {
break;
}
}

let _wpt_server = WPTServer(proc);

for (suite_name, includes) in config.into_iter() {
let suite_path = util::wpt_path().join(suite_name);
let dir = WalkDir::new(&suite_path)
Expand Down Expand Up @@ -5337,14 +5420,15 @@ fn web_platform_tests() {
})
.collect();

let mut variants: Vec<&str> = test_file_text
let mut variants: Vec<String> = test_file_text
.split('\n')
.into_iter()
.filter_map(|t| t.strip_prefix("// META: variant="))
.map(|t| format!("?{}", t))
.collect();

if variants.is_empty() {
variants.push("");
variants.push("".to_string());
}

for variant in variants {
Expand All @@ -5367,11 +5451,19 @@ fn web_platform_tests() {
let bundle = concat_bundle(files, file.path(), "".to_string());
file.write_all(bundle.as_bytes()).unwrap();

let self_path = test_file_path.strip_prefix(util::wpt_path()).unwrap();

let child = util::deno_cmd()
.current_dir(test_file_path.parent().unwrap())
.arg("run")
.arg("--location")
.arg(&format!("http://web-platform-tests/?{}", variant))
.arg(&format!(
"http://web-platform.test:8000/{}{}",
self_path.to_str().unwrap(),
variant
))
.arg("--cert")
.arg(util::wpt_path().join("tools/certs/cacert.pem"))
.arg("-A")
.arg(file.path())
.arg(deno_core::serde_json::to_string(&expect_fail).unwrap())
Expand Down
4 changes: 2 additions & 2 deletions cli/tests/unit/net_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function netTcpListenCloseWhileIterating(): Promise<void> {
const listener = Deno.listen({ port: 8000 });
const listener = Deno.listen({ port: 8001 });
const nextWhileClosing = listener[Symbol.asyncIterator]().next();
listener.close();
assertEquals(await nextWhileClosing, { value: undefined, done: true });
Expand All @@ -437,7 +437,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function netUdpListenCloseWhileIterating(): Promise<void> {
const socket = Deno.listenDatagram({ port: 8000, transport: "udp" });
const socket = Deno.listenDatagram({ port: 8001, transport: "udp" });
const nextWhileClosing = socket[Symbol.asyncIterator]().next();
socket.close();
assertEquals(await nextWhileClosing, { value: undefined, done: true });
Expand Down
Loading