From 19a9b603cb5d0e6bcc844c732893ecdcaf7bf5c4 Mon Sep 17 00:00:00 2001 From: mcapuccini Date: Tue, 1 Mar 2022 13:11:52 +0000 Subject: [PATCH 1/5] Add CI test --- .ci/tests/mnist-keras/is_success.py | 32 ++++++++++++++++ .ci/tests/mnist-keras/run.sh | 57 +++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 .ci/tests/mnist-keras/is_success.py create mode 100755 .ci/tests/mnist-keras/run.sh diff --git a/.ci/tests/mnist-keras/is_success.py b/.ci/tests/mnist-keras/is_success.py new file mode 100644 index 000000000..ff92ab522 --- /dev/null +++ b/.ci/tests/mnist-keras/is_success.py @@ -0,0 +1,32 @@ +from tkinter import N +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 From 973577ea53a4c23608b5d531d751e083d68c1209 Mon Sep 17 00:00:00 2001 From: mcapuccini Date: Tue, 1 Mar 2022 13:16:16 +0000 Subject: [PATCH 2/5] Add CI workflow --- .github/workflows/integration-tests.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/workflows/integration-tests.yaml diff --git a/.github/workflows/integration-tests.yaml b/.github/workflows/integration-tests.yaml new file mode 100644 index 000000000..777f2ea40 --- /dev/null +++ b/.github/workflows/integration-tests.yaml @@ -0,0 +1,13 @@ +name: "branch name check" + +on: push + +jobs: + branch-name-check: + runs-on: ubuntu-20.04 + steps: + - name: checkout + uses: actions/checkout@v2 + + - name: test mnist-keras example + run: .ci/tests/mnist-keras.sh \ No newline at end of file From 236c206899dba3ec98cc500e00e9c348f979e034 Mon Sep 17 00:00:00 2001 From: mcapuccini Date: Tue, 1 Mar 2022 13:19:39 +0000 Subject: [PATCH 3/5] rename --- .github/workflows/integration-tests.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/integration-tests.yaml b/.github/workflows/integration-tests.yaml index 777f2ea40..8b04857bc 100644 --- a/.github/workflows/integration-tests.yaml +++ b/.github/workflows/integration-tests.yaml @@ -1,9 +1,9 @@ -name: "branch name check" +name: "integration tests" on: push jobs: - branch-name-check: + integration-tests: runs-on: ubuntu-20.04 steps: - name: checkout From b0b1196a2563320770bdeea232fd4798b208e00b Mon Sep 17 00:00:00 2001 From: mcapuccini Date: Tue, 1 Mar 2022 13:20:16 +0000 Subject: [PATCH 4/5] Fix path --- .github/workflows/integration-tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration-tests.yaml b/.github/workflows/integration-tests.yaml index 8b04857bc..00f6903b4 100644 --- a/.github/workflows/integration-tests.yaml +++ b/.github/workflows/integration-tests.yaml @@ -10,4 +10,4 @@ jobs: uses: actions/checkout@v2 - name: test mnist-keras example - run: .ci/tests/mnist-keras.sh \ No newline at end of file + run: .ci/tests/mnist-keras/run.sh \ No newline at end of file From 34403efd290ae78a27f16aa1d1ef1eaa717064e5 Mon Sep 17 00:00:00 2001 From: mcapuccini Date: Tue, 1 Mar 2022 13:26:03 +0000 Subject: [PATCH 5/5] fix import --- .ci/tests/mnist-keras/is_success.py | 1 - 1 file changed, 1 deletion(-) diff --git a/.ci/tests/mnist-keras/is_success.py b/.ci/tests/mnist-keras/is_success.py index ff92ab522..90cb7c1c2 100644 --- a/.ci/tests/mnist-keras/is_success.py +++ b/.ci/tests/mnist-keras/is_success.py @@ -1,4 +1,3 @@ -from tkinter import N import pymongo from time import sleep import sys