Skip to content

Commit

Permalink
add e2e tests for php, python, swift, oci, longevity
Browse files Browse the repository at this point in the history
  • Loading branch information
rajatjindal committed Mar 1, 2023
1 parent 0d48649 commit 064851c
Show file tree
Hide file tree
Showing 15 changed files with 365 additions and 40 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ E2E_TESTS_DOCKERFILE ?= e2e-tests.Dockerfile
MYSQL_IMAGE ?= mysql:8.0.22
REDIS_IMAGE ?= redis:7.0.8-alpine3.17
POSTGRES_IMAGE ?= postgres:14.7-alpine

REGISTRY_IMAGE ?= registry:2
## overrides for aarch64
ifneq ($(ARCH),x86_64)
MYSQL_IMAGE = arm64v8/mysql:8.0.32
REDIS_IMAGE = arm64v8/redis:6.0-alpine3.17
POSTGRES_IMAGE = arm64v8/postgres:14.7
REGISTRY_IMAGE = arm64v8/registry:2
E2E_TESTS_DOCKERFILE = e2e-tests-aarch64.Dockerfile
endif

Expand Down
27 changes: 27 additions & 0 deletions crates/e2e-testing/src/spin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,33 @@ pub fn install_plugins(plugins: Vec<&str>) -> Result<Output> {
Ok(output)
}

pub fn registry_push(appname: &str, registry_app_url: &str) -> Result<Output> {
let appdir = appdir(appname);
utils::run(
vec!["spin", "registry", "push", registry_app_url, "--insecure"],
Some(&appdir),
None,
)
}

// use docker login until https:/fermyon/spin/issues/1211
pub fn registry_login(registry_url: &str, username: &str, password: &str) -> Result<Output> {
utils::run(
vec![
"spin",
"registry",
"login",
"-u",
username,
"-p",
password,
registry_url,
],
None,
None,
)
}

pub fn build_app(appname: &str) -> Result<Output> {
let appdir = appdir(appname);
utils::run(vec!["spin", "build"], Some(&appdir), None)
Expand Down
9 changes: 9 additions & 0 deletions crates/e2e-testing/src/testcase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ pub struct TestCase {

/// assertions to run once the app is running
pub assertions: ChecksFunc,

/// registry app url where app is pushed and run from
#[builder(default)]
pub push_to_registry: Option<String>,
}

impl TestCase {
Expand Down Expand Up @@ -118,6 +122,11 @@ impl TestCase {
// run spin build
controller.build_app(&appname).context("building app")?;

//push to registry if url provided
if let Some(registry_app_url) = &self.push_to_registry {
spin::registry_push(&appname, registry_app_url.as_str())?;
}

// run `spin up` (or `spin deploy` for cloud).
// `AppInstance` has some basic info about the running app like base url, routes (only for cloud) etc.
let deploy_args = self.deploy_args.iter().map(|s| s as &str).collect();
Expand Down
3 changes: 1 addition & 2 deletions crates/e2e-testing/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ pub async fn wait_tcp(url: &str, process: &mut tokio::process::Child, target: &s

match TcpStream::connect(&url).await {
Ok(_) => break,
Err(e) => {
println!("connect {} error {}, retry {}", &url, e, wait_count);
Err(_) => {
wait_count += 1;
sleep(Duration::from_secs(1)).await;
}
Expand Down
30 changes: 18 additions & 12 deletions e2e-tests-aarch64.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ARG BUILD_SPIN=false
ARG SPIN_VERSION=canary

WORKDIR /root
RUN apt-get update && apt-get install -y wget sudo xz-utils gcc git pkg-config redis
RUN apt-get update && apt-get install -y wget sudo xz-utils gcc git pkg-config redis clang libicu-dev docker.io

# nodejs
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
Expand Down Expand Up @@ -44,27 +44,33 @@ RUN url="https://static.rust-lang.org/rustup/dist/aarch64-unknown-linux-gnu/rust
rustc --version; \
rustup target add wasm32-wasi;

# swift
RUN wget https:/swiftwasm/swift/releases/download/swift-wasm-5.8-SNAPSHOT-2023-02-24-a/swift-wasm-5.8-SNAPSHOT-2023-02-24-a-ubuntu20.04_aarch64.tar.gz && \
tar -xf swift-wasm-5.8-SNAPSHOT-2023-02-24-a-ubuntu20.04_aarch64.tar.gz
ENV PATH="$PATH:/root/swift-wasm-5.8-SNAPSHOT-2023-02-24-a/usr/bin"

## check versions
RUN tinygo version; \
go version; \
zig version; \
rustc --version; \
node --version;
node --version; \
swift --version;

## spin
RUN wget https:/fermyon/spin/releases/download/${SPIN_VERSION}/spin-${SPIN_VERSION}-linux-aarch64.tar.gz && \
tar -xvf spin-${SPIN_VERSION}-linux-aarch64.tar.gz && \
ls -ltr && \
mv spin /usr/local/bin/spin;

WORKDIR /e2e-tests
COPY . .

# spin
RUN if [ "${BUILD_SPIN}" != "true" ]; then \
wget https:/fermyon/spin/releases/download/${SPIN_VERSION}/spin-${SPIN_VERSION}-linux-aarch64.tar.gz && \
tar -xvf spin-${SPIN_VERSION}-linux-aarch64.tar.gz && \
ls -ltr && \
mv spin /usr/local/bin/spin; \
else \
cargo build --release && \
cp target/release/spin /usr/local/bin/spin; \
RUN if [ "${BUILD_SPIN}" == "true" ]; then \
cargo build --release && \
cp target/release/spin /usr/local/bin/spin; \
fi

RUN spin --version

CMD cargo test spinup_tests --features new-e2e-tests --no-fail-fast -- --nocapture
CMD cargo test spinup_tests --features e2e-tests --no-fail-fast -- --nocapture
11 changes: 10 additions & 1 deletion e2e-tests-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,20 @@ services:
- "6379:6379"
restart: always

registry:
image: ${REGISTRY_IMAGE:-registry:2}
ports:
- "5000:5000"
restart: always
environment:
- REGISTRY_HTTP_SECRET=secret

e2e-tests:
depends_on:
- mysql
- redis
- postgres
- registry
image: spin-e2e-tests
entrypoint: cargo test spinup_tests --features e2e-tests --no-fail-fast -- --nocapture
volumes:
Expand All @@ -49,4 +58,4 @@ volumes:
postgres_data: {}
cargo_registry_cache: {}
cargo_git_cache: {}
target_cache: {}
target_cache: {}
61 changes: 37 additions & 24 deletions e2e-tests.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
FROM ubuntu:22.04

ARG BUILD_SPIN=false
ARG SPIN_VERSION=canary

WORKDIR /root
RUN apt-get update && apt-get install -y wget sudo xz-utils gcc git pkg-config redis
RUN apt-get update && apt-get install -y wget sudo xz-utils gcc git pkg-config redis clang libicu-dev docker.io

# nodejs
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
Expand All @@ -26,38 +29,48 @@ ENV PATH="$PATH:/root/zig-linux-x86_64-0.10.0"
RUN wget https:/grain-lang/grain/releases/download/grain-v0.5.4/grain-linux-x64 && \
mv grain-linux-x64 /usr/local/bin/grain && chmod +x /usr/local/bin/grain

# spin
RUN wget https:/fermyon/spin/releases/download/canary/spin-canary-linux-amd64.tar.gz && \
tar -xvf spin-canary-linux-amd64.tar.gz && \
ls -ltr && \
mv spin /usr/local/bin/spin

# # rust
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH

RUN url="https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init"; \
wget "$url"; \
chmod +x rustup-init; \
./rustup-init -y --no-modify-path --default-toolchain 1.66 --default-host x86_64-unknown-linux-gnu; \
rm rustup-init; \
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \
rustup --version; \
cargo --version; \
rustc --version; \
RUN url="https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init"; \
wget "$url"; \
chmod +x rustup-init; \
./rustup-init -y --no-modify-path --default-toolchain 1.66 --default-host x86_64-unknown-linux-gnu; \
rm rustup-init; \
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \
rustup --version; \
cargo --version; \
rustc --version; \
rustup target add wasm32-wasi;

# swift
RUN wget https:/swiftwasm/swift/releases/download/swift-wasm-5.8-SNAPSHOT-2023-02-24-a/swift-wasm-5.8-SNAPSHOT-2023-02-24-a-ubuntu22.04_x86_64.tar.gz && \
tar -xf swift-wasm-5.8-SNAPSHOT-2023-02-24-a-ubuntu22.04_x86_64.tar.gz
ENV PATH="$PATH:/root/swift-wasm-5.8-SNAPSHOT-2023-02-24-a/usr/bin"

## check versions
RUN tinygo version
RUN go version
RUN grain --version
RUN spin --version
RUN zig version
RUN rustc --version
RUN node --version
RUN tinygo version; \
go version; \
zig version; \
rustc --version; \
node --version; \
swift --version;

RUN wget https:/fermyon/spin/releases/download/${SPIN_VERSION}/spin-${SPIN_VERSION}-linux-aarch64.tar.gz && \
tar -xvf spin-${SPIN_VERSION}-linux-aarch64.tar.gz && \
ls -ltr && \
mv spin /usr/local/bin/spin;

WORKDIR /e2e-tests
COPY . .

CMD cargo test spinup_tests --features new-e2e-tests --no-fail-fast -- --nocapture
RUN if [ "${BUILD_SPIN}" == "true" ]; then \
cargo build --release && \
cp target/release/spin /usr/local/bin/spin; \
fi

RUN spin --version

CMD cargo test spinup_tests --features e2e-tests --no-fail-fast -- --nocapture
26 changes: 26 additions & 0 deletions tests/spinup_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ mod spinup_tests {
testcases::all::http_js_works(CONTROLLER).await
}

#[tokio::test]
async fn http_python_works() {
testcases::all::http_python_works(CONTROLLER).await
}

#[tokio::test]
#[ignore] // https:/fermyon/spin/issues/1210
async fn http_php_works() {
testcases::all::http_php_works(CONTROLLER).await
}

#[tokio::test]
async fn http_swift_works() {
testcases::all::http_swift_works(CONTROLLER).await
}

#[tokio::test]
async fn assets_routing_works() {
testcases::all::assets_routing_works(CONTROLLER).await
Expand Down Expand Up @@ -85,4 +101,14 @@ mod spinup_tests {
async fn redis_rust_works() {
testcases::all::redis_rust_works(CONTROLLER).await
}

#[tokio::test]
async fn registry_works() {
testcases::all::registry_works(CONTROLLER).await
}

#[tokio::test]
async fn longevity_apps_works() {
testcases::all::longevity_apps_works(CONTROLLER).await
}
}
12 changes: 12 additions & 0 deletions tests/testcases/longevity-apps-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## longevity-apps-test

longevity test is to ensure `wasm` file(s) compiled with a version of `Spin` continues to work with runtime of future version of `Spin`.

The current wasm files are created using following templates with `Spin v0.9.0`

- http-go
- http-rust
- http-js
- http-ts

The `wasm` files are built using `spin build` and copied over here for validation.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
30 changes: 30 additions & 0 deletions tests/testcases/longevity-apps-test/spin.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
spin_version = "1"
authors = ["Fermyon Engineering <[email protected]>"]
description = "A longevity test for verifying backward compatible runtime"
name = "longevity-test"
trigger = {type = "http", base = "/"}
version = "1.0.0"

[[component]]
id = "go"
source = "longevity-go.wasm"
[component.trigger]
route = "/golang/..."

[[component]]
id = "rust"
source = "longevity-rust.wasm"
[component.trigger]
route = "/rust/..."

[[component]]
id = "typescript"
source = "longevity-typescript.wasm"
[component.trigger]
route = "/typescript/..."

[[component]]
id = "javascript"
source = "longevity-javascript.wasm"
[component.trigger]
route = "/javascript/..."
Loading

0 comments on commit 064851c

Please sign in to comment.