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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unit tests for the opcodes version of futex used by http server #3694

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
102 changes: 102 additions & 0 deletions tests/integration/cli/tests/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,13 @@ static WEBC_PYTHON: &[u8] = include_bytes!("./webc/python-0.1.0.webc");
static WEBC_WEB_SERVER: &[u8] = include_bytes!(
"./webc/static-web-server-async-1.0.3-5d739d1a-20b7-4edf-8cf4-44e813f96b25.webc"
);
static WEBC_WEB_SERVER_OPCODES: &'static [u8] = include_bytes!(
"./webc/static-web-server-opcodes-1.0.8-454915f4-2823-4ddf-a784-1c5f58950c46.webc"
);
static WEBC_WASMER_SH: &[u8] =
include_bytes!("./webc/wasmer-sh-1.0.63-dd3d67d1-de94-458c-a9ee-caea3b230ccf.webc");
static WEBC_WASMER_SH_OPCODES: &'static [u8] =
include_bytes!("./webc/wasmer-sh-opcodes-1.0.63-f3551836-16c9-4ccd-83bd-ab697efe5dcd.webc");

impl std::fmt::Debug for TestSpec {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Expand Down Expand Up @@ -771,6 +776,103 @@ fn test_snapshot_web_server_epoll() {
assert_json_snapshot!(snapshot);
}

#[cfg(not(any(target_env = "musl", target_os = "macos", target_os = "windows")))]
#[test]
fn test_snapshot_web_server_opcodes() {
let with_inner = || {
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()?;

let http_get = |url, max_retries| {
rt.block_on(async move {
for n in 0..(max_retries+1) {
println!("http request: {}", url);
tokio::select! {
resp = reqwest::get(url) => {
let resp = match resp {
Ok(a) => a,
Err(_) if n < max_retries => {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
continue;
}
Err(err) => return Err(err.into())
};
if resp.status().is_success() == false {
return Err(anyhow::format_err!("incorrect status code: {}", resp.status()));
}
return Ok(resp.bytes().await?);
}
_ = tokio::time::sleep(std::time::Duration::from_secs(1)) => {
eprintln!("retrying request... ({} attempts)", n);
continue;
}
}
}
Err(anyhow::format_err!("timeout while performing HTTP request"))
})
};

let expected_size = usize::from_str_radix(
String::from_utf8_lossy(http_get("http://localhost:7778/main.js.size", 50)?.as_ref())
.trim(),
10,
)?;
if expected_size == 0 {
return Err(anyhow::format_err!("There was no data returned"));
}
println!("expected_size: {}", expected_size);

let reference_data = http_get("http://localhost:7778/main.js", 0)?;
for _ in 0..20 {
let test_data = http_get("http://localhost:7778/main.js", 0)?;
println!("actual_size: {}", test_data.len());

if expected_size != test_data.len() {
return Err(anyhow::format_err!(
"The actual size and expected size does not match {} vs {}",
test_data.len(),
expected_size
));
}
if test_data
.iter()
.zip(reference_data.iter())
.any(|(a, b)| a != b)
{
return Err(anyhow::format_err!("The returned data is inconsistent"));
}
}

Ok(0)
};

let with = move |mut child: Child| {
let ret = with_inner();
child.kill().ok();
ret
};

let snapshot = TestBuilder::new()
.with_name(function!())
.enable_network(true)
.include_static_package(
"sharrattj/static-web-server-opcodes@1.0.8",
WEBC_WEB_SERVER_OPCODES,
)
.include_static_package("sharrattj/wasmer-sh-opcodes@1.0.63", WEBC_WASMER_SH_OPCODES)
.use_coreutils()
.use_pkg("sharrattj/wasmer-sh-opcodes")
.stdin_str(
r#"
cat /public/main.js | wc -c > /public/main.js.size
rm -f /cfg/config.toml
/bin/webserver --log-level warn --root /public --port 7778"#,
)
.run_wasm_with(include_bytes!("./wasm/dash.wasm"), Box::new(with));
assert_json_snapshot!(snapshot);
}

#[cfg_attr(
any(target_env = "musl", target_os = "macos", target_os = "windows"),
ignore
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
---
source: tests/integration/cli/tests/snapshot.rs
assertion_line: 670
expression: snapshot
---
{
"spec": {
"name": "snapshot::test_snapshot_web_server_opcodes",
"use_packages": [
"sharrattj/coreutils",
"sharrattj/wasmer-sh-opcodes"
],
"include_webcs": [
{
"name": "sharrattj/static-web-server-opcodes@1.0.8"
},
{
"name": "sharrattj/wasmer-sh-opcodes@1.0.63"
},
{
"name": "sharrattj/coreutils@1.0.16"
}
],
"cli_args": [],
"stdin": [
10,
99,
97,
116,
32,
47,
112,
117,
98,
108,
105,
99,
47,
109,
97,
105,
110,
46,
106,
115,
32,
124,
32,
119,
99,
32,
45,
99,
32,
62,
32,
47,
112,
117,
98,
108,
105,
99,
47,
109,
97,
105,
110,
46,
106,
115,
46,
115,
105,
122,
101,
10,
114,
109,
32,
45,
102,
32,
47,
99,
102,
103,
47,
99,
111,
110,
102,
105,
103,
46,
116,
111,
109,
108,
10,
47,
98,
105,
110,
47,
119,
101,
98,
115,
101,
114,
118,
101,
114,
32,
45,
45,
108,
111,
103,
45,
108,
101,
118,
101,
108,
32,
119,
97,
114,
110,
32,
45,
45,
114,
111,
111,
116,
32,
47,
112,
117,
98,
108,
105,
99,
32,
45,
45,
112,
111,
114,
116,
32,
55,
55,
55,
56
],
"debug_output": false,
"enable_threads": true,
"enable_network": true
},
"result": {
"Success": {
"stdout": "",
"stderr": "# # # # ",
"exit_code": 0
}
}
}
Binary file not shown.
Binary file not shown.
Loading