Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the simulator server workspace root dir #2533

Merged
merged 3 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nvflare/private/fed/app/simulator/simulator_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def client_run(self, clients, gpu):

def start_server_app(self, args):
app_server_root = os.path.join(self.simulator_root, "server", SimulatorConstants.JOB_NAME, "app_server")
args.workspace = app_server_root
args.workspace = os.path.join(self.simulator_root, "server")
yhwen marked this conversation as resolved.
Show resolved Hide resolved
os.chdir(args.workspace)

log_file = os.path.join(self.simulator_root, "server", WorkspaceConstants.LOG_FILE_NAME)
Expand Down
39 changes: 37 additions & 2 deletions tests/unit_test/private/fed/app/simulator/simulator_runner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@

import os
import shutil
import threading
import time
import uuid
from unittest.mock import patch
from tempfile import TemporaryDirectory
from unittest.mock import Mock, patch

import pytest

from nvflare.apis.fl_constant import WorkspaceConstants
from nvflare.apis.fl_constant import FLContextKey, MachineStatus, WorkspaceConstants
from nvflare.private.fed.app.simulator.simulator_runner import SimulatorRunner
from nvflare.private.fed.utils.fed_utils import split_gpus

Expand All @@ -28,6 +31,9 @@ class MockCell:
def get_root_url_for_child(self):
return "tcp://0:123"

def get_internal_listener_url(self):
return "tcp://0:123"


class TestSimulatorRunner:
def setup_method(self, method):
Expand Down Expand Up @@ -120,3 +126,32 @@ def test_split_gpus_success(self, gpus, expected_gpus):
def test_split_gpus_fail(self, gpus):
with pytest.raises(ValueError):
split_gpus(gpus)

@patch("nvflare.private.fed.app.deployer.simulator_deployer.SimulatorServer.deploy")
@patch("nvflare.private.fed.app.utils.FedAdminServer")
@patch("nvflare.private.fed.client.fed_client.FederatedClient.register")
@patch("nvflare.private.fed.server.fed_server.BaseServer.get_cell", return_value=MockCell())
def test_start_server_app(self, mock_deploy, mock_admin, mock_register, mock_cell):
with TemporaryDirectory() as workspace:
job_folder = os.path.join(os.path.dirname(__file__), "../../../../data/jobs/valid_job")
runner = SimulatorRunner(
job_folder=job_folder,
workspace=workspace,
)
runner.setup()

with patch("nvflare.private.fed.simulator.simulator_server.SimulatorServer.run_engine"):
with patch("nvflare.private.fed.simulator.simulator_server.SimulatorServer.create_job_cell"):
server_thread = threading.Thread(target=runner.start_server_app, args=[runner.args])
server_thread.start()

while runner.server.engine.engine_info.status != MachineStatus.STARTED:
time.sleep(1.0)
if not server_thread.is_alive():
raise RuntimeError("Could not start the Server App.")
fl_ctx = runner.server.engine.new_context()
workspace_obj = fl_ctx.get_prop(FLContextKey.WORKSPACE_OBJECT)
assert workspace_obj.get_root_dir() == os.path.join(workspace, "server")

runner.server.logger = Mock()
runner.server.engine.asked_to_stop = True
Loading