From dc5c2fd15fb601e44987022871a0e0a825fe733f Mon Sep 17 00:00:00 2001 From: Mohsin Zaidi <2236875+smrz2001@users.noreply.github.com> Date: Wed, 6 Sep 2023 15:01:39 -0400 Subject: [PATCH] feat: add workflows for property-based testing --- .github/workflows/test.yml | 13 +++++++++---- Makefile | 4 ---- ci-scripts/build-test-binaries.sh | 8 ++++---- entrypoint.sh | 6 ++---- k8s/tests/scripts/run-tests.sh | 12 ++++++++++-- tests/api.rs | 2 +- 6 files changed, 26 insertions(+), 19 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a681b8ab..5c094c88 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,14 +42,19 @@ jobs: with: cluster_name: ${{ secrets.GKE_CLUSTER }} location: ${{ secrets.GKE_ZONE }} + - + # Add a "_sha_runId" suffix to differentiate test runs + name: Setup test env + run: | + TEST_SUFFIX="-$(echo ${{ github.sha }} | head -c 12)-${{ github.run_id }}" + echo "TEST_SUFFIX=$TEST_SUFFIX" >> $GITHUB_ENV - name: Test ${{ matrix.networks }} working-directory: k8s/tests/scripts - run: | - # Add a "_sha_runId" suffix to differentiate test runs - TEST_SUFFIX="_$(echo ${{ github.sha }} | head -c 12)_${{ github.run_id }}" - ./run-tests.sh ${{ matrix.networks }} + run: ./run-tests.sh ${{ matrix.networks }} - + # Always cleanup resources at the end, whether the tests pass or fail. name: Delete ${{ matrix.networks }} + if: always() working-directory: k8s/tests/scripts run: ./delete-tests.sh ${{ matrix.networks }} diff --git a/Makefile b/Makefile index 4fe5cf67..23384a23 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,3 @@ check-clippy: publish-docker: ./ci-scripts/publish.sh -.PHONY: -publish-docker: - ./ci-scripts/publish.sh - diff --git a/ci-scripts/build-test-binaries.sh b/ci-scripts/build-test-binaries.sh index ff0d19b8..2dcd3467 100755 --- a/ci-scripts/build-test-binaries.sh +++ b/ci-scripts/build-test-binaries.sh @@ -1,7 +1,7 @@ #!/bin/bash BUILD_MODE=$1 -if [ -z $BUILD_MODE ] +if [ -z "$BUILD_MODE" ] then echo "Must pass build mode arg" exit 1 @@ -12,11 +12,11 @@ mkdir test-binaries for b in $(RUSTFLAGS='-D warnings' cargo test \ --no-run \ --locked \ - --profile $BUILD_MODE \ + --profile "$BUILD_MODE" \ -q \ --message-format=json \ | jq -r 'select(.executable != null) | .executable') do - echo $b - cp $b test-binaries/ + echo "$b" + cp "$b" test-binaries/ done diff --git a/entrypoint.sh b/entrypoint.sh index 4c6e8a8a..46cd1bad 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -6,8 +6,6 @@ set -e for tb in /test-binaries/* do echo "Running tests in: $tb" - $tb + # Always exit successfully so that the test job isn't restarted + $tb || exit 0 done - -# Always exit successfully so that the test job isn't restarted -exit 0 diff --git a/k8s/tests/scripts/run-tests.sh b/k8s/tests/scripts/run-tests.sh index 194c878a..f14515f4 100755 --- a/k8s/tests/scripts/run-tests.sh +++ b/k8s/tests/scripts/run-tests.sh @@ -9,9 +9,17 @@ yq " # Create the network. kubectl create configmap check-network --from-file=check-network.sh -n "keramik-$1$TEST_SUFFIX" -yq ".metadata.name = \"keramik-$1$TEST_SUFFIX\"" ../../networks/"$1".yaml | kubectl apply -f - +yq ".metadata.name = \"$1$TEST_SUFFIX\"" ../../networks/"$1".yaml | kubectl apply -f - # Create the test job kubectl apply -f ../manifests/tests.yaml -n "keramik-$1$TEST_SUFFIX" -# Wait for tests to complete \ No newline at end of file +# Wait for tests to complete then collect the results +kubectl wait --for=condition=complete job/ceramic-tests -n "keramik-$1$TEST_SUFFIX" --timeout=20m +TEST_RESULTS=$(kubectl logs job.batch/ceramic-tests -c ceramic-tests -n "keramik-$1$TEST_SUFFIX") +echo "$TEST_RESULTS" +# Return a failure from here instead of from the tests. The test job is setup to restart on failure, which is needed for +# it to be setup correctly with the right Ceramic/ComposeDB URLs. +if [[ "$TEST_RESULTS" =~ "FAILED" ]]; then + exit 1 +fi diff --git a/tests/api.rs b/tests/api.rs index 24c5d0e3..7a0b02cb 100644 --- a/tests/api.rs +++ b/tests/api.rs @@ -12,7 +12,7 @@ use tokio::sync::OnceCell; use tracing_test::traced_test; use url::Url; -use rust_ceramic_migration_tests::ceramic::{composedb_client, ComposeDbClient}; +use ceramic_tests::ceramic::{composedb_client, ComposeDbClient}; const CERAMIC_URLS: &str = "CERAMIC_URLS"; const COMPOSEDB_URLS: &str = "COMPOSEDB_URLS";