-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests with Redis (#11)
* Setting up a Redis instance in the integration tests github workflow * Making an integration test for end-to-end training
- Loading branch information
Showing
7 changed files
with
80 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ jobs: | |
source $(poetry env info --path)/bin/activate | ||
poetry install --with docs,test | ||
cd docs && rm -rf source/reference/api/_autosummary && make html | ||
cd .. && coverage run -m pytest -m "not integration_test" && coverage xml && coverage report -m | ||
cd .. && coverage run -m pytest florist/tests/unit && coverage xml && coverage report -m | ||
# - name: Upload coverage to Codecov | ||
# uses: Wandalen/[email protected] | ||
# with: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ jobs: | |
source $(poetry env info --path)/bin/activate | ||
poetry install --with docs,test | ||
cd docs && rm -rf source/reference/api/_autosummary && make html | ||
cd .. && coverage run -m pytest -m "not integration_test" && coverage xml && coverage report -m | ||
cd .. && coverage run -m pytest florist/tests/unit && coverage xml && coverage report -m | ||
# - name: Upload coverage to Codecov | ||
# uses: Wandalen/[email protected] | ||
# with: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,10 @@ jobs: | |
- uses: actions/[email protected] | ||
with: | ||
python-version: '3.9' | ||
- name: Setup redis | ||
uses: supercharge/[email protected] | ||
with: | ||
redis-version: 7.2.4 | ||
- name: Install dependencies and check code | ||
run: | | ||
poetry env use '3.9' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import json | ||
import tempfile | ||
from functools import partial | ||
from unittest.mock import ANY | ||
|
||
from florist.api import client | ||
from florist.api.launchers.local import launch_server | ||
from florist.tests.utils.api.launch_utils import get_server | ||
|
||
|
||
def test_train(): | ||
test_server_address = "0.0.0.0:8080" | ||
|
||
with tempfile.TemporaryDirectory() as temp_dir: | ||
server_constructor = partial(get_server, n_clients=1) | ||
server_log_file = f"{temp_dir}/server.out" | ||
server_process = launch_server(server_constructor, test_server_address, 2, server_log_file) | ||
|
||
test_client = "MNIST" | ||
test_data_path = f"{temp_dir}/data" | ||
test_redis_host = "localhost" | ||
test_redis_port = "6379" | ||
|
||
response = client.start(test_server_address, test_client, test_data_path, test_redis_host, test_redis_port) | ||
|
||
assert json.loads(response.body.decode()) == {"uuid": ANY} | ||
|
||
server_process.join() | ||
|
||
with open(server_log_file, "r") as f: | ||
file_contents = f.read() | ||
assert "FL finished in" in file_contents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from functools import partial | ||
from typing import Callable, Dict | ||
|
||
from fl4health.server.base_server import FlServer | ||
|
||
from florist.tests.utils.api.fl4health_utils import get_server_fedavg | ||
from florist.api.clients.mnist import MnistNet | ||
|
||
|
||
def fit_config(batch_size: int, local_epochs: int, current_server_round: int) -> Dict[str, int]: | ||
return { | ||
"batch_size": batch_size, | ||
"current_server_round": current_server_round, | ||
"local_epochs": local_epochs, | ||
} | ||
|
||
|
||
def get_server( | ||
fit_config: Callable[..., Dict[str, int]] = fit_config, | ||
n_clients: int = 2, | ||
batch_size: int = 8, | ||
local_epochs: int = 1, | ||
) -> FlServer: | ||
fit_config_fn = partial(fit_config, batch_size, local_epochs) | ||
server = get_server_fedavg(model=MnistNet(), n_clients=n_clients, fit_config_fn=fit_config_fn) | ||
return server |