diff --git a/.ci/tests/mnist-keras/is_success.py b/.ci/tests/mnist-keras/is_success.py new file mode 100644 index 000000000..90cb7c1c2 --- /dev/null +++ b/.ci/tests/mnist-keras/is_success.py @@ -0,0 +1,31 @@ +import pymongo +from time import sleep +import sys + +N_ROUNDS = 3 +RETRIES= 6 +SLEEP=10 + +def _eprint(*args, **kwargs): + print(*args, file=sys.stderr, **kwargs) + +def _wait_n_rounds(collection): + n = 0 + for _ in range(RETRIES): + query = {'reducer.status': 'Success'} + n = collection.count_documents(query) + if n == N_ROUNDS: + return n + _eprint(f'Succeded rounds {n}. Sleeping for {SLEEP}.') + sleep(SLEEP) + _eprint(f'Succeded rounds: {n}. Giving up.') + return n + +if __name__ == '__main__': + # Connect to mongo + client = pymongo.MongoClient("mongodb://fedn_admin:password@localhost:6534") + + # Wait for successful rounds + succeded = _wait_n_rounds(client['fedn-test-network']['control']['round']) + assert(succeded == N_ROUNDS) # check that all rounds succeeded + _eprint(f'Succeded rounds: {succeded}. Test passed.') \ No newline at end of file diff --git a/.ci/tests/mnist-keras/run.sh b/.ci/tests/mnist-keras/run.sh new file mode 100755 index 000000000..d3dfccc98 --- /dev/null +++ b/.ci/tests/mnist-keras/run.sh @@ -0,0 +1,57 @@ +#!/bin/bash +set -e + +>&2 echo "Configuring mnist-keras environment" +pushd examples/mnist-keras +bin/init_venv.sh + +>&2 echo "Download and prepare data" +bin/get_data +bin/split_data + +>&2 echo "Build compute package and seed" +bin/build.sh + +>&2 echo "Start FEDn" +docker-compose \ + -f ../../docker-compose.yaml \ + -f docker-compose.override.yaml \ + up -d + +>&2 echo "Wait for reducer to start" +sleep 10 # TODO: add API call to check when ready + +>&2 echo "Upload compute package" +curl -k -X POST \ + -F file=@package.tgz \ + -F helper=keras \ + https://localhost:8090/context +printf '\n' + +>&2 echo "Upload seed" +curl -k -X POST \ + -F seed=@seed.npz \ + https://localhost:8090/models +printf '\n' + +>&2 echo "Wait for clients to connect" +sleep 10 # TODO: add API call to check when ready + +>&2 echo "Start round" +curl -k -X POST \ + -F rounds=3 \ + -F validate=True \ + https://localhost:8090/control +printf '\n' + +>&2 echo "Checking rounds success" +.mnist-keras/bin/python ../../.ci/tests/mnist-keras/is_success.py + +>&2 echo "Stop FEDn" +docker-compose \ + -f ../../docker-compose.yaml \ + -f docker-compose.override.yaml \ + down + +popd +>&2 echo "Test completed successfully" \ No newline at end of file diff --git a/.github/workflows/integration-tests.yaml b/.github/workflows/integration-tests.yaml new file mode 100644 index 000000000..00f6903b4 --- /dev/null +++ b/.github/workflows/integration-tests.yaml @@ -0,0 +1,13 @@ +name: "integration tests" + +on: push + +jobs: + integration-tests: + runs-on: ubuntu-20.04 + steps: + - name: checkout + uses: actions/checkout@v2 + + - name: test mnist-keras example + run: .ci/tests/mnist-keras/run.sh \ No newline at end of file