From 4016d9d9d65e02451c9051c455f876e74819b0c7 Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Tue, 23 May 2023 11:27:14 +0200 Subject: [PATCH 01/18] feat: add e2e tests to check different examples are working properly --- .github/workflows/build.yml | 11 +++++-- Cargo.lock | 11 +++++++ Cargo.toml | 3 ++ examples/Makefile | 2 +- tests/e2e.rs | 64 +++++++++++++++++++++++++++++++++++++ 5 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 tests/e2e.rs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8f840c2f..00c47f45 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,7 +30,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 @@ -42,10 +42,17 @@ jobs: ~/.cargo/git target key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Build Rust examples + working-directory: ./examples + run: make all - name: Test run: cargo test --workspace --exclude wasm-workers-quick-js-engine build: - runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 - name: Build diff --git a/Cargo.lock b/Cargo.lock index cf198478..4ded4779 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1139,6 +1139,12 @@ version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608" +[[package]] +name = "futures-io" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" + [[package]] name = "futures-sink" version = "0.3.26" @@ -1158,9 +1164,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1" dependencies = [ "futures-core", + "futures-io", "futures-task", + "memchr", "pin-project-lite", "pin-utils", + "slab", ] [[package]] @@ -2585,6 +2594,7 @@ dependencies = [ "libc", "memchr", "mio", + "num_cpus", "parking_lot", "pin-project-lite", "signal-hook-registry", @@ -2956,6 +2966,7 @@ dependencies = [ "env_logger 0.9.3", "openssl", "prettytable-rs", + "reqwest", "wws-config", "wws-router", "wws-runtimes-manager", diff --git a/Cargo.toml b/Cargo.toml index a2d0c13a..3418510f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,9 @@ wws-router = { workspace = true } wws-server = { workspace = true } wws-runtimes-manager = { workspace = true } +[dev-dependencies] +reqwest = { version = "0.11", features = ["blocking"] } + [target.x86_64-unknown-linux-musl.dependencies] openssl = { version = "=0.10.48", features = ["vendored"] } diff --git a/examples/Makefile b/examples/Makefile index 9d239cda..6ae334d2 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -20,4 +20,4 @@ pdf-create: cargo build --target wasm32-wasi --release && \ mv target/wasm32-wasi/release/pdf-create.wasm ./index.wasm -all: rust-basic rust-kv rust-params pdf-create +all: rust-basic rust-kv rust-params diff --git a/tests/e2e.rs b/tests/e2e.rs new file mode 100644 index 00000000..d1e53b16 --- /dev/null +++ b/tests/e2e.rs @@ -0,0 +1,64 @@ + +#[cfg(test)] +mod test { + use std::process::{Command, Stdio, Child}; + use std::path::PathBuf; + use std::{thread, time, io}; + + fn run_debug(example_path: &str) -> io::Result { + let path = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); + + Command::new(path.join("target/debug/wws")) + .arg(path.join(example_path)) + .stdout(Stdio::piped()) + .spawn() + } + + fn sleep_for(seconds: u64) { + thread::sleep(time::Duration::from_secs(seconds)); + } + + fn request_body(url: &str) -> Result { + reqwest::blocking::get(url)? + .text() + } + + // Check the examples/js-json works + fn run_end_to_end_test(example: &str, waiting_seconds: u64, url: &str, expected_text: &str) { + let mut child = run_debug(example) + .expect("Failed to execute command"); + + sleep_for(waiting_seconds); + + let body = match request_body(url) { + Ok(body) => body, + Err(err) => { + eprintln!("Error getting the body from the request to {url}"); + eprintln!("Error: {}", err); + String::new() + } + }; + + // Test + assert!(body.contains(expected_text)); + + println!("Stopping wws process [{}]", &child.id()); + child.kill().expect("Error stopping wws"); + } + + #[test] + // Use this approach to run tests sequentially + fn test_end_to_end() { + let tests = [ + ("examples/js-basic", 10, "http://localhost:8080", "This page was generated by a JavaScript file"), + ("examples/js-json", 10, "http://localhost:8080/handler", "This message comes from an environment variable"), + ("examples/js-params", 25, "http://localhost:8080/thisisatest", "thisisatest"), + ("examples/rust-basic", 10, "http://localhost:8080/basic", "This page was generated by a Wasm module built from Rust"), + ("examples/rust-kv", 10, "http://localhost:8080/kv", "Counter: 0"), + ]; + + for (example, waiting_seconds, url, expected_text) in tests { + run_end_to_end_test(example, waiting_seconds, url, expected_text); + } + } +} \ No newline at end of file From 7098bb2954ecafc2a7ef89c540c4e2245c55daf7 Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Tue, 23 May 2023 11:38:48 +0200 Subject: [PATCH 02/18] fix: add wasm32-wasi target on the CI and format code --- .github/workflows/build.yml | 2 ++ tests/e2e.rs | 48 +++++++++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 00c47f45..4f0bfa6a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,6 +42,8 @@ jobs: ~/.cargo/git target key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Install Wasm32-wasi target + run: rustup target add wasm32-wasi - name: Build Rust examples working-directory: ./examples run: make all diff --git a/tests/e2e.rs b/tests/e2e.rs index d1e53b16..ebe783c8 100644 --- a/tests/e2e.rs +++ b/tests/e2e.rs @@ -1,9 +1,8 @@ - #[cfg(test)] mod test { - use std::process::{Command, Stdio, Child}; use std::path::PathBuf; - use std::{thread, time, io}; + use std::process::{Child, Command, Stdio}; + use std::{io, thread, time}; fn run_debug(example_path: &str) -> io::Result { let path = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); @@ -19,14 +18,12 @@ mod test { } fn request_body(url: &str) -> Result { - reqwest::blocking::get(url)? - .text() + reqwest::blocking::get(url)?.text() } // Check the examples/js-json works fn run_end_to_end_test(example: &str, waiting_seconds: u64, url: &str, expected_text: &str) { - let mut child = run_debug(example) - .expect("Failed to execute command"); + let mut child = run_debug(example).expect("Failed to execute command"); sleep_for(waiting_seconds); @@ -50,15 +47,40 @@ mod test { // Use this approach to run tests sequentially fn test_end_to_end() { let tests = [ - ("examples/js-basic", 10, "http://localhost:8080", "This page was generated by a JavaScript file"), - ("examples/js-json", 10, "http://localhost:8080/handler", "This message comes from an environment variable"), - ("examples/js-params", 25, "http://localhost:8080/thisisatest", "thisisatest"), - ("examples/rust-basic", 10, "http://localhost:8080/basic", "This page was generated by a Wasm module built from Rust"), - ("examples/rust-kv", 10, "http://localhost:8080/kv", "Counter: 0"), + ( + "examples/js-basic", + 10, + "http://localhost:8080", + "This page was generated by a JavaScript file", + ), + ( + "examples/js-json", + 10, + "http://localhost:8080/handler", + "This message comes from an environment variable", + ), + ( + "examples/js-params", + 25, + "http://localhost:8080/thisisatest", + "thisisatest", + ), + ( + "examples/rust-basic", + 10, + "http://localhost:8080/basic", + "This page was generated by a Wasm module built from Rust", + ), + ( + "examples/rust-kv", + 10, + "http://localhost:8080/kv", + "Counter: 0", + ), ]; for (example, waiting_seconds, url, expected_text) in tests { run_end_to_end_test(example, waiting_seconds, url, expected_text); } } -} \ No newline at end of file +} From 80abb5e0090aea5b61b1efc97a7c74de0a13b7f4 Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Tue, 23 May 2023 12:01:05 +0200 Subject: [PATCH 03/18] fix: make e2e timeouts configurable on the CI --- .github/workflows/build.yml | 4 +++- tests/e2e.rs | 24 ++++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4f0bfa6a..5a75b4ea 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -32,6 +32,8 @@ jobs: matrix: os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} + env: + E2E_WAITING_TIME: 30 steps: - uses: actions/checkout@v3 - name: Caching @@ -48,7 +50,7 @@ jobs: working-directory: ./examples run: make all - name: Test - run: cargo test --workspace --exclude wasm-workers-quick-js-engine + run: cargo test --workspace --exclude wasm-workers-quick-js-engine -- --show-output build: strategy: fail-fast: false diff --git a/tests/e2e.rs b/tests/e2e.rs index ebe783c8..879189d9 100644 --- a/tests/e2e.rs +++ b/tests/e2e.rs @@ -2,7 +2,7 @@ mod test { use std::path::PathBuf; use std::process::{Child, Command, Stdio}; - use std::{io, thread, time}; + use std::{io, thread, time, env}; fn run_debug(example_path: &str) -> io::Result { let path = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); @@ -46,34 +46,46 @@ mod test { #[test] // Use this approach to run tests sequentially fn test_end_to_end() { + // Allow configuring waiting times. It avoids having long waiting times + // in development, while making it configurable in the CI + let global_timeout: Option = match env::var("E2E_WAITING_TIME") { + Ok(val) => { + match val.parse::() { + Ok(val) => Some(val), + Err(_) => None + } + }, + Err(_) => None + }; + let tests = [ ( "examples/js-basic", - 10, + global_timeout.unwrap_or(10), "http://localhost:8080", "This page was generated by a JavaScript file", ), ( "examples/js-json", - 10, + global_timeout.unwrap_or(10), "http://localhost:8080/handler", "This message comes from an environment variable", ), ( "examples/js-params", - 25, + global_timeout.unwrap_or(25), "http://localhost:8080/thisisatest", "thisisatest", ), ( "examples/rust-basic", - 10, + global_timeout.unwrap_or(10), "http://localhost:8080/basic", "This page was generated by a Wasm module built from Rust", ), ( "examples/rust-kv", - 10, + global_timeout.unwrap_or(10), "http://localhost:8080/kv", "Counter: 0", ), From 62cc591596279ded7158b94bf384dc3eb154a547 Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Tue, 23 May 2023 12:05:05 +0200 Subject: [PATCH 04/18] fix: format code correctly --- tests/e2e.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/e2e.rs b/tests/e2e.rs index 879189d9..20e6ba68 100644 --- a/tests/e2e.rs +++ b/tests/e2e.rs @@ -2,7 +2,7 @@ mod test { use std::path::PathBuf; use std::process::{Child, Command, Stdio}; - use std::{io, thread, time, env}; + use std::{env, io, thread, time}; fn run_debug(example_path: &str) -> io::Result { let path = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); @@ -49,13 +49,11 @@ mod test { // Allow configuring waiting times. It avoids having long waiting times // in development, while making it configurable in the CI let global_timeout: Option = match env::var("E2E_WAITING_TIME") { - Ok(val) => { - match val.parse::() { - Ok(val) => Some(val), - Err(_) => None - } + Ok(val) => match val.parse::() { + Ok(val) => Some(val), + Err(_) => None, }, - Err(_) => None + Err(_) => None, }; let tests = [ From 4c2f03ce93b424cce1c4d98afe54cfa210a03b52 Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Tue, 23 May 2023 12:17:03 +0200 Subject: [PATCH 05/18] feat: use wws release binary when available on e2e tests --- .github/workflows/build.yml | 16 ++++------------ tests/e2e.rs | 9 ++++++++- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5a75b4ea..3be37e21 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,14 +26,14 @@ jobs: run: cargo fmt --check - name: Clippy run: cargo clippy -- -D warnings - test: + build: strategy: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} env: - E2E_WAITING_TIME: 30 + E2E_WAITING_TIME: 20 steps: - uses: actions/checkout@v3 - name: Caching @@ -49,15 +49,7 @@ jobs: - name: Build Rust examples working-directory: ./examples run: make all + - name: Build wws on release mode + run: cargo build --verbose --release - name: Test run: cargo test --workspace --exclude wasm-workers-quick-js-engine -- --show-output - build: - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v3 - - name: Build - run: cargo build --verbose \ No newline at end of file diff --git a/tests/e2e.rs b/tests/e2e.rs index 20e6ba68..8f765204 100644 --- a/tests/e2e.rs +++ b/tests/e2e.rs @@ -7,7 +7,14 @@ mod test { fn run_debug(example_path: &str) -> io::Result { let path = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); - Command::new(path.join("target/debug/wws")) + // Use release when it's available + let wws_path = if path.join("target/release/wws").exists() { + path.join("target/release/wws") + } else { + path.join("target/debug/wws") + }; + + Command::new(path.join(wws_path)) .arg(path.join(example_path)) .stdout(Stdio::piped()) .spawn() From 571cb225f4e7aee8dca6af244f9d4bd1aa8a8bb3 Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Tue, 23 May 2023 12:42:26 +0200 Subject: [PATCH 06/18] fix: avoid using / in e2e for windows compatibility --- tests/e2e.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/e2e.rs b/tests/e2e.rs index 8f765204..6df38544 100644 --- a/tests/e2e.rs +++ b/tests/e2e.rs @@ -15,7 +15,7 @@ mod test { }; Command::new(path.join(wws_path)) - .arg(path.join(example_path)) + .arg(path.join("examples").join(example_path)) .stdout(Stdio::piped()) .spawn() } @@ -65,31 +65,31 @@ mod test { let tests = [ ( - "examples/js-basic", + "js-basic", global_timeout.unwrap_or(10), "http://localhost:8080", "This page was generated by a JavaScript file", ), ( - "examples/js-json", + "js-json", global_timeout.unwrap_or(10), "http://localhost:8080/handler", "This message comes from an environment variable", ), ( - "examples/js-params", + "js-params", global_timeout.unwrap_or(25), "http://localhost:8080/thisisatest", "thisisatest", ), ( - "examples/rust-basic", + "rust-basic", global_timeout.unwrap_or(10), "http://localhost:8080/basic", "This page was generated by a Wasm module built from Rust", ), ( - "examples/rust-kv", + "rust-kv", global_timeout.unwrap_or(10), "http://localhost:8080/kv", "Counter: 0", From ae4744165e56c3a2daba3b048c0d3a3521f63006 Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Tue, 23 May 2023 13:08:50 +0200 Subject: [PATCH 07/18] fix: configure wws binary to run in Windows --- tests/e2e.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/e2e.rs b/tests/e2e.rs index 6df38544..6df71bcf 100644 --- a/tests/e2e.rs +++ b/tests/e2e.rs @@ -4,6 +4,7 @@ mod test { use std::process::{Child, Command, Stdio}; use std::{env, io, thread, time}; + #[cfg(not(target_os = "windows"))] fn run_debug(example_path: &str) -> io::Result { let path = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); @@ -14,6 +15,27 @@ mod test { path.join("target/debug/wws") }; + println!("Running wws from {}", wws_path.display()); + + Command::new(path.join(wws_path)) + .arg(path.join("examples").join(example_path)) + .stdout(Stdio::piped()) + .spawn() + } + + #[cfg(target_os = "windows")] + fn run_debug(example_path: &str) -> io::Result { + let path = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); + + // Use release when it's available + let wws_path = if path.join("target\\release\\wws.exe").exists() { + path.join("target\\release\\wws.exe") + } else { + path.join("target\\debug\\wws.exe") + }; + + println!("Running wws from {}", wws_path.display()); + Command::new(path.join(wws_path)) .arg(path.join("examples").join(example_path)) .stdout(Stdio::piped()) From 1c0a9eed4b333990cab853a67e27be0df1cadb80 Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Tue, 23 May 2023 13:54:07 +0200 Subject: [PATCH 08/18] feat: redirect stderr on e2e tests and increase the timeouts in Windows --- .github/workflows/build.yml | 9 ++++++++- tests/e2e.rs | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3be37e21..c1848751 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,9 +31,16 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] + include: + - os: ubuntu-latest + e2e_time: 20 + - os: macos-latest + e2e_time: 20 + - os: windows-latest + e2e_time: 30 runs-on: ${{ matrix.os }} env: - E2E_WAITING_TIME: 20 + E2E_WAITING_TIME: ${{ matrix.e2e_time }} steps: - uses: actions/checkout@v3 - name: Caching diff --git a/tests/e2e.rs b/tests/e2e.rs index 6df71bcf..5f2a84b0 100644 --- a/tests/e2e.rs +++ b/tests/e2e.rs @@ -20,6 +20,7 @@ mod test { Command::new(path.join(wws_path)) .arg(path.join("examples").join(example_path)) .stdout(Stdio::piped()) + .stderr(Stdio::piped()) .spawn() } @@ -39,6 +40,7 @@ mod test { Command::new(path.join(wws_path)) .arg(path.join("examples").join(example_path)) .stdout(Stdio::piped()) + .stderr(Stdio::piped()) .spawn() } From 8684e0fb71a21a5cbdf725e9443d09d98b7c4627 Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Tue, 23 May 2023 14:22:29 +0200 Subject: [PATCH 09/18] fix: increase Windows e2e timeout and print body --- .github/workflows/build.yml | 2 +- tests/e2e.rs | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c1848751..f187c59b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -37,7 +37,7 @@ jobs: - os: macos-latest e2e_time: 20 - os: windows-latest - e2e_time: 30 + e2e_time: 60 runs-on: ${{ matrix.os }} env: E2E_WAITING_TIME: ${{ matrix.e2e_time }} diff --git a/tests/e2e.rs b/tests/e2e.rs index 5f2a84b0..fcfc9a46 100644 --- a/tests/e2e.rs +++ b/tests/e2e.rs @@ -67,6 +67,8 @@ mod test { } }; + println!("Body content: {body}"); + // Test assert!(body.contains(expected_text)); @@ -88,6 +90,18 @@ mod test { }; let tests = [ + ( + "rust-basic", + global_timeout.unwrap_or(10), + "http://localhost:8080/basic", + "This page was generated by a Wasm module built from Rust", + ), + ( + "rust-kv", + global_timeout.unwrap_or(10), + "http://localhost:8080/kv", + "Counter: 0", + ), ( "js-basic", global_timeout.unwrap_or(10), @@ -106,18 +120,6 @@ mod test { "http://localhost:8080/thisisatest", "thisisatest", ), - ( - "rust-basic", - global_timeout.unwrap_or(10), - "http://localhost:8080/basic", - "This page was generated by a Wasm module built from Rust", - ), - ( - "rust-kv", - global_timeout.unwrap_or(10), - "http://localhost:8080/kv", - "Counter: 0", - ), ]; for (example, waiting_seconds, url, expected_text) in tests { From 11f3b91ed54250448cb545b6b46a848ad926b90a Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Thu, 25 May 2023 08:24:42 +0200 Subject: [PATCH 10/18] fix: remove unnecesary matrix element. Reduce timeouts --- .github/workflows/build.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f187c59b..6eca7613 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,14 +30,13 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest] include: - os: ubuntu-latest - e2e_time: 20 + e2e_time: 10 - os: macos-latest - e2e_time: 20 + e2e_time: 10 - os: windows-latest - e2e_time: 60 + e2e_time: 20 runs-on: ${{ matrix.os }} env: E2E_WAITING_TIME: ${{ matrix.e2e_time }} From b3cc38087c72554c1beb94d04ffdd89fad93c1f6 Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Thu, 25 May 2023 10:20:22 +0200 Subject: [PATCH 11/18] feat: add ruby and python e2e tests. Reuse wws release from cache --- .github/workflows/build.yml | 23 +++++---- examples/ruby-basic/.wws.toml | 44 +++++++++++++++++ tests/e2e.rs | 91 +++++++++++++++++++++++++---------- 3 files changed, 123 insertions(+), 35 deletions(-) create mode 100644 examples/ruby-basic/.wws.toml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6eca7613..9415794c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,16 +30,8 @@ jobs: strategy: fail-fast: false matrix: - include: - - os: ubuntu-latest - e2e_time: 10 - - os: macos-latest - e2e_time: 10 - - os: windows-latest - e2e_time: 20 + os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} - env: - E2E_WAITING_TIME: ${{ matrix.e2e_time }} steps: - uses: actions/checkout@v3 - name: Caching @@ -55,7 +47,20 @@ jobs: - name: Build Rust examples working-directory: ./examples run: make all + - name: Check existing wws release (Unix) + id: check_file_release + if: matrix.os != "windows-latest" + uses: andstor/file-existence-action@v2 + with: + files: "target/release/wws" + - name: Check existing wws release (Windows) + if: matrix.os == "windows-latest" + id: check_file_release + uses: andstor/file-existence-action@v2 + with: + files: "target/release/wws.exe" - name: Build wws on release mode + if: steps.check_file_release.outputs.files_exists == 'false' run: cargo build --verbose --release - name: Test run: cargo test --workspace --exclude wasm-workers-quick-js-engine -- --show-output diff --git a/examples/ruby-basic/.wws.toml b/examples/ruby-basic/.wws.toml new file mode 100644 index 00000000..773b70a6 --- /dev/null +++ b/examples/ruby-basic/.wws.toml @@ -0,0 +1,44 @@ +version = 1 + +[[repositories]] +name = "wasmlabs" +url = "https://workers.wasmlabs.dev/repository/v1/index.toml" + +[[repositories.runtimes]] +name = "ruby" +version = "3.2.0+20230215-1" +tags = [ + "latest", + "3.2", + "3.2.0", +] +status = "active" +extensions = ["rb"] +args = [ + "--", + "/src/index.rb", +] + +[repositories.runtimes.binary] +url = "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/ruby%2F3.2.0%2B20230215-1349da9/ruby-3.2.0.wasm" +filename = "ruby.wasm" + +[repositories.runtimes.binary.checksum] +type = "sha256" +value = "abe348fba157a756f86194be445c77c99e8ed64ca76495ea07ed984f09eb66ae" + +[repositories.runtimes.polyfill] +url = "https://workers.wasmlabs.dev/repository/v1/files/ruby/3-1/poly.rb" +filename = "poly.rb" + +[repositories.runtimes.polyfill.checksum] +type = "sha256" +value = "449855a5d315879ab0ad830aa6a3f689e68fed4490617ea03efc77c9da64f630" + +[repositories.runtimes.wrapper] +url = "https://workers.wasmlabs.dev/repository/v1/files/ruby/3-1/wrapper.txt" +filename = "wrapper.txt" + +[repositories.runtimes.wrapper.checksum] +type = "sha256" +value = "6d808b4747cf30f82665a38a47e1176513bbdd6ad558c09db03d719e33ad2da0" diff --git a/tests/e2e.rs b/tests/e2e.rs index fcfc9a46..f92a3387 100644 --- a/tests/e2e.rs +++ b/tests/e2e.rs @@ -5,7 +5,7 @@ mod test { use std::{env, io, thread, time}; #[cfg(not(target_os = "windows"))] - fn run_debug(example_path: &str) -> io::Result { + fn get_wws_path() -> PathBuf { let path = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); // Use release when it's available @@ -15,30 +15,43 @@ mod test { path.join("target/debug/wws") }; - println!("Running wws from {}", wws_path.display()); + println!("[E2E] Running wws from {}", wws_path.display()); - Command::new(path.join(wws_path)) - .arg(path.join("examples").join(example_path)) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() + wws_path } #[cfg(target_os = "windows")] - fn run_debug(example_path: &str) -> io::Result { + fn get_wws_path() -> PathBuf { let path = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); // Use release when it's available - let wws_path = if path.join("target\\release\\wws.exe").exists() { - path.join("target\\release\\wws.exe") + let wws_path = if path.join("target/release/wws.exe").exists() { + path.join("target/release/wws.exe") } else { - path.join("target\\debug\\wws.exe") + path.join("target/debug/wws.exe") }; - println!("Running wws from {}", wws_path.display()); + println!("[E2E] Running wws from {}", wws_path.display()); + + wws_path + } - Command::new(path.join(wws_path)) - .arg(path.join("examples").join(example_path)) + fn run(example_path: &str) -> io::Result { + let path = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); + let example_path = path.join("examples").join(example_path); + let wws_path = get_wws_path(); + + // Install missing runtimes + Command::new(&wws_path) + .current_dir(&example_path) + .args(["runtimes", "install"]) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn()?; + + // Run the example + Command::new(&wws_path) + .arg(&example_path) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .spawn() @@ -54,26 +67,28 @@ mod test { // Check the examples/js-json works fn run_end_to_end_test(example: &str, waiting_seconds: u64, url: &str, expected_text: &str) { - let mut child = run_debug(example).expect("Failed to execute command"); + println!("[E2E] Running example: {example}"); + + let mut child = run(example).expect("Failed to execute command"); sleep_for(waiting_seconds); let body = match request_body(url) { Ok(body) => body, Err(err) => { - eprintln!("Error getting the body from the request to {url}"); - eprintln!("Error: {}", err); + eprintln!("[E2E] Error getting the body from the request to {url}"); + eprintln!("[E2E] Error: {}", err); String::new() } }; - println!("Body content: {body}"); + println!("[E2E] Body content: {body}"); + + println!("[E2E] Stopping wws process [{}]", &child.id()); + child.kill().expect("Error stopping wws"); // Test assert!(body.contains(expected_text)); - - println!("Stopping wws process [{}]", &child.id()); - child.kill().expect("Error stopping wws"); } #[test] @@ -92,34 +107,58 @@ mod test { let tests = [ ( "rust-basic", - global_timeout.unwrap_or(10), + global_timeout.unwrap_or(5), "http://localhost:8080/basic", "This page was generated by a Wasm module built from Rust", ), ( "rust-kv", - global_timeout.unwrap_or(10), + global_timeout.unwrap_or(5), "http://localhost:8080/kv", "Counter: 0", ), + ( + "rust-params", + global_timeout.unwrap_or(5), + "http://localhost:8080/thisisatest", + "thisisatest", + ), ( "js-basic", - global_timeout.unwrap_or(10), + global_timeout.unwrap_or(5), "http://localhost:8080", "This page was generated by a JavaScript file", ), ( "js-json", - global_timeout.unwrap_or(10), + global_timeout.unwrap_or(5), "http://localhost:8080/handler", "This message comes from an environment variable", ), ( "js-params", - global_timeout.unwrap_or(25), + global_timeout.unwrap_or(10), "http://localhost:8080/thisisatest", "thisisatest", ), + ( + "python-basic", + global_timeout.unwrap_or(10), + "http://localhost:8080/", + "This page was generated by a Python script", + ), + ( + "python-mount", + global_timeout.unwrap_or(10), + "http://localhost:8080/", + "This page was loaded from a mounted file", + ), + ( + "ruby-basic", + global_timeout.unwrap_or(10), + "http://localhost:8080/", + "This page was generated by a Ruby script", + ), ]; for (example, waiting_seconds, url, expected_text) in tests { From c9e854d89adaec9a8b485c1545030b31a10ec88a Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Thu, 25 May 2023 10:25:47 +0200 Subject: [PATCH 12/18] fix: use a bash script to check if the release file exists --- .github/workflows/build.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9415794c..6f8cddce 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,17 +50,19 @@ jobs: - name: Check existing wws release (Unix) id: check_file_release if: matrix.os != "windows-latest" - uses: andstor/file-existence-action@v2 - with: - files: "target/release/wws" + run: | + if test -f "target/release/wws"; then + echo "files_exists=true" >> $GITHUB_OUTPUT + fi - name: Check existing wws release (Windows) if: matrix.os == "windows-latest" id: check_file_release - uses: andstor/file-existence-action@v2 - with: - files: "target/release/wws.exe" + run: | + if test -f "target/release/wws.exe"; then + echo "files_exists=true" >> $GITHUB_OUTPUT + fi - name: Build wws on release mode - if: steps.check_file_release.outputs.files_exists == 'false' + if: steps.check_file_release.outputs.files_exists != 'true' run: cargo build --verbose --release - name: Test run: cargo test --workspace --exclude wasm-workers-quick-js-engine -- --show-output From c3111b6efb47fb3867ebbf996c8c8b338f50d152 Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Thu, 25 May 2023 10:33:39 +0200 Subject: [PATCH 13/18] fix: remove file detection as cache should be enough --- .github/workflows/build.yml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6f8cddce..1386b69b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,20 +47,6 @@ jobs: - name: Build Rust examples working-directory: ./examples run: make all - - name: Check existing wws release (Unix) - id: check_file_release - if: matrix.os != "windows-latest" - run: | - if test -f "target/release/wws"; then - echo "files_exists=true" >> $GITHUB_OUTPUT - fi - - name: Check existing wws release (Windows) - if: matrix.os == "windows-latest" - id: check_file_release - run: | - if test -f "target/release/wws.exe"; then - echo "files_exists=true" >> $GITHUB_OUTPUT - fi - name: Build wws on release mode if: steps.check_file_release.outputs.files_exists != 'true' run: cargo build --verbose --release From b468c05c2ed16946278c9751f6fa6b85dc01a3f5 Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Thu, 25 May 2023 11:02:58 +0200 Subject: [PATCH 14/18] fix: increase timeouts for interpreted e2e tests and inherith the Stdio --- tests/e2e.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/e2e.rs b/tests/e2e.rs index f92a3387..6d2ef1e4 100644 --- a/tests/e2e.rs +++ b/tests/e2e.rs @@ -42,18 +42,20 @@ mod test { let wws_path = get_wws_path(); // Install missing runtimes + println!("[E2E] Installing missing runtimes"); Command::new(&wws_path) .current_dir(&example_path) .args(["runtimes", "install"]) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) .spawn()?; // Run the example + println!("[E2E] Running the service"); Command::new(&wws_path) .arg(&example_path) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) .spawn() } @@ -143,19 +145,19 @@ mod test { ), ( "python-basic", - global_timeout.unwrap_or(10), + global_timeout.unwrap_or(20), "http://localhost:8080/", "This page was generated by a Python script", ), ( "python-mount", - global_timeout.unwrap_or(10), + global_timeout.unwrap_or(20), "http://localhost:8080/", "This page was loaded from a mounted file", ), ( "ruby-basic", - global_timeout.unwrap_or(10), + global_timeout.unwrap_or(20), "http://localhost:8080/", "This page was generated by a Ruby script", ), From b25b9cb008bd718971caae2707b65b0a10651886 Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Thu, 25 May 2023 11:10:59 +0200 Subject: [PATCH 15/18] fix: wait for wws to install the runtimes --- tests/e2e.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/e2e.rs b/tests/e2e.rs index 6d2ef1e4..2f0671f1 100644 --- a/tests/e2e.rs +++ b/tests/e2e.rs @@ -48,14 +48,12 @@ mod test { .args(["runtimes", "install"]) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) - .spawn()?; + .status()?; // Run the example println!("[E2E] Running the service"); Command::new(&wws_path) .arg(&example_path) - .stdout(Stdio::inherit()) - .stderr(Stdio::inherit()) .spawn() } From 20d63036b32b4b896972d3b93f7d818e66774578 Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Thu, 25 May 2023 11:12:34 +0200 Subject: [PATCH 16/18] fix: format the file correctly --- tests/e2e.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/e2e.rs b/tests/e2e.rs index 2f0671f1..0dc63d0a 100644 --- a/tests/e2e.rs +++ b/tests/e2e.rs @@ -52,9 +52,7 @@ mod test { // Run the example println!("[E2E] Running the service"); - Command::new(&wws_path) - .arg(&example_path) - .spawn() + Command::new(&wws_path).arg(&example_path).spawn() } fn sleep_for(seconds: u64) { From 3d0f5d92f6c498417e89c61707e87ed6ef230fc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20M?= Date: Thu, 25 May 2023 11:26:30 +0200 Subject: [PATCH 17/18] format: improve E2E_WAITING_TIME load MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rafael Fernández López --- tests/e2e.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/e2e.rs b/tests/e2e.rs index 0dc63d0a..43392f52 100644 --- a/tests/e2e.rs +++ b/tests/e2e.rs @@ -94,13 +94,7 @@ mod test { fn test_end_to_end() { // Allow configuring waiting times. It avoids having long waiting times // in development, while making it configurable in the CI - let global_timeout: Option = match env::var("E2E_WAITING_TIME") { - Ok(val) => match val.parse::() { - Ok(val) => Some(val), - Err(_) => None, - }, - Err(_) => None, - }; + let global_timeout = env::var("E2E_WAITING_TIME").map(|str| str.parse::())).ok(); let tests = [ ( From 37d7fcf5046dac44ce8f3033d61e082358547587 Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Thu, 25 May 2023 12:00:38 +0200 Subject: [PATCH 18/18] fix: use the right types when parsing the E2E_WAITING_TIME env variable --- tests/e2e.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/e2e.rs b/tests/e2e.rs index 43392f52..51b2d890 100644 --- a/tests/e2e.rs +++ b/tests/e2e.rs @@ -94,7 +94,10 @@ mod test { fn test_end_to_end() { // Allow configuring waiting times. It avoids having long waiting times // in development, while making it configurable in the CI - let global_timeout = env::var("E2E_WAITING_TIME").map(|str| str.parse::())).ok(); + let global_timeout = + env::var("E2E_WAITING_TIME").map_or(None, |str| str.parse::().ok()); + + // env (Result(String)) -> map () let tests = [ (