From fceeb939c1b4feed9952d40ad5470eba27ed1dcb Mon Sep 17 00:00:00 2001 From: Daniyar Itegulov Date: Fri, 14 Jul 2023 13:32:01 +1000 Subject: [PATCH 1/4] exclude integration tests from docker image --- .dockerignore | 1 + Dockerfile | 1 + 2 files changed, 2 insertions(+) diff --git a/.dockerignore b/.dockerignore index 84b95f7f2..e26a8aa6f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -7,3 +7,4 @@ target/ Dockerfile .dockerignore infra/ +integration-tests/ diff --git a/Dockerfile b/Dockerfile index 15665992a..f7258c408 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ COPY mpc-recovery/Cargo.toml Cargo.toml RUN sed -i 's#src/main.rs#dummy.rs#' Cargo.toml RUN cargo build --release COPY . . +RUN sed -i 's#"integration-tests",##' Cargo.toml RUN cargo build --release --package mpc-recovery FROM debian:bullseye-slim as runtime From f4dcc01c42b473bd19744f87ff73bb7e13a43d48 Mon Sep 17 00:00:00 2001 From: Daniyar Itegulov Date: Fri, 14 Jul 2023 13:32:18 +1000 Subject: [PATCH 2/4] use env_logger for running tests --- Cargo.lock | 21 +++++++++++++++++++++ integration-tests/Cargo.toml | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index ac99678fb..1ae9d72c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1398,6 +1398,19 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "env_logger" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + [[package]] name = "errno" version = "0.3.1" @@ -1975,6 +1988,12 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "hyper" version = "0.14.26" @@ -2433,6 +2452,7 @@ dependencies = [ "clap 4.3.5", "curv-kzen", "ed25519-dalek", + "env_logger", "futures", "hex 0.4.3", "hyper", @@ -2451,6 +2471,7 @@ dependencies = [ "tokio", "tokio-util 0.7.3", "tracing", + "tracing-log", "tracing-subscriber", "workspaces", ] diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 32891bc12..1ea454af8 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -28,7 +28,9 @@ workspaces = { git = "https://github.com/near/workspaces-rs", branch = "main" } [dev-dependencies] once_cell = "1" rand = "0.8" -test-log = { version = "0.2.12", default-features = false, features = ["trace"] } +test-log = { version = "0.2.12", features = ["log", "trace"] } +env_logger = "0.10.0" +tracing-log = "0.1.3" tokio-util = { version = "0.7", features = ["full"] } curv = { package = "curv-kzen", version = "0.9", default-features = false } reqwest = "0.11.16" From b5c15c0b9d6891ef00e0a8e60499919adc8c6a85 Mon Sep 17 00:00:00 2001 From: Daniyar Itegulov Date: Fri, 14 Jul 2023 13:32:27 +1000 Subject: [PATCH 3/4] add macos ci workflow --- ...{integration_tests.yml => integration.yml} | 19 +++++++++++++++++-- .github/workflows/{tests.yml => unit.yml} | 4 ++-- 2 files changed, 19 insertions(+), 4 deletions(-) rename .github/workflows/{integration_tests.yml => integration.yml} (71%) rename .github/workflows/{tests.yml => unit.yml} (97%) diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration.yml similarity index 71% rename from .github/workflows/integration_tests.yml rename to .github/workflows/integration.yml index 44c58e0b7..a03b2fb10 100644 --- a/.github/workflows/integration_tests.yml +++ b/.github/workflows/integration.yml @@ -1,4 +1,4 @@ -name: Integration tests +name: Integration on: push: branches: @@ -9,10 +9,20 @@ env: RUSTFLAGS: -D warnings jobs: test: - runs-on: ubuntu-latest + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.os }} name: Test steps: - uses: actions/checkout@v3 + - name: Install Docker + if: ${{ matrix.os == 'macos-latest' }} + run: | + brew install docker + colima start + # + sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock - name: Login to GitHub Container Registry uses: docker/login-action@v1 with: @@ -33,6 +43,8 @@ jobs: - uses: Swatinem/rust-cache@v1 - name: Install Protoc uses: arduino/setup-protoc@v1.1.2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} - name: Build Docker image uses: docker/build-push-action@v4 with: @@ -43,3 +55,6 @@ jobs: cache-to: type=gha,mode=max - name: Test run: cargo test -p mpc-recovery-integration-tests --jobs 1 -- --test-threads 1 + env: + RUST_LOG: trace + RUST_BACKTRACE: 1 \ No newline at end of file diff --git a/.github/workflows/tests.yml b/.github/workflows/unit.yml similarity index 97% rename from .github/workflows/tests.yml rename to .github/workflows/unit.yml index 2de3f533b..2012e0071 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/unit.yml @@ -1,4 +1,4 @@ -name: Unit tests +name: Unit on: push: branches: @@ -10,7 +10,7 @@ env: jobs: test: runs-on: ubuntu-latest - name: Test + name: Check & Test steps: - uses: actions/checkout@v3 - name: Install stable toolchain From 6e2ef79f88c2adaf99f14735448c3c4585183aa7 Mon Sep 17 00:00:00 2001 From: Daniyar Itegulov Date: Fri, 14 Jul 2023 15:37:16 +1000 Subject: [PATCH 4/4] wait for sandbox deterministically --- integration-tests/src/containers.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/integration-tests/src/containers.rs b/integration-tests/src/containers.rs index 369516ae1..3a0c2ddd3 100644 --- a/integration-tests/src/containers.rs +++ b/integration-tests/src/containers.rs @@ -114,11 +114,11 @@ impl<'a> Sandbox<'a> { tracing::info!("Running sandbox container..."); #[cfg(all(target_os = "macos", target_arch = "aarch64"))] let image = GenericImage::new("ghcr.io/near/sandbox", "latest-aarch64") - .with_wait_for(WaitFor::seconds(2)) + .with_wait_for(WaitFor::Nothing) .with_exposed_port(Self::CONTAINER_RPC_PORT); #[cfg(target_arch = "x86_64")] let image = GenericImage::new("ghcr.io/near/sandbox", "latest") - .with_wait_for(WaitFor::seconds(2)) + .with_wait_for(WaitFor::Nothing) .with_exposed_port(Self::CONTAINER_RPC_PORT); let image: RunnableImage = ( image, @@ -136,6 +136,11 @@ impl<'a> Sandbox<'a> { .get_network_ip_address(&container, network) .await?; + container.exec(ExecCommand { + cmd: format!("bash -c 'while [[ \"$(curl -s -o /dev/null -w ''%{{http_code}}'' localhost:{})\" != \"200\" ]]; do sleep 1; done'", Self::CONTAINER_RPC_PORT), + ready_conditions: vec![] + }); + let full_address = format!("http://{}:{}", address, Self::CONTAINER_RPC_PORT); tracing::info!("Sandbox container is running at {}", full_address); Ok(Sandbox {