Skip to content

Commit

Permalink
Made improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ZohebShaikh committed Jan 17, 2025
1 parent 0d433b1 commit 92f5800
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/blueapi/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,10 @@ def env(
# Reload the environment if needed
print("Reloading environment")
status = client.reload_environment(timeout=timeout)
print("Environment is initialized")
else:
status = client.get_environment()

print(status)


Expand Down
4 changes: 2 additions & 2 deletions src/blueapi/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,9 @@ def _wait_for_reload(
f"Error reloading environment: {status.error_message}"
)
elif (
status.initialized and status.environment_id != previous_environment_id
status.initialized is True
and status.environment_id != previous_environment_id
):
print("Environment is initialized")
return status
time.sleep(polling_interval)
# If the function did not raise or return early, it timed out
Expand Down
12 changes: 6 additions & 6 deletions src/blueapi/service/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,38 +71,38 @@ def reload(self):

@start_as_current_span(TRACER)
def start(self):
new_environment_id = uuid.uuid4()
environment_id = uuid.uuid4()
try:
self._subprocess = self._subprocess_factory()
self.run(setup, self._config)
self._state = EnvironmentResponse(
environment_id=new_environment_id,
environment_id=environment_id,
initialized=True,
)
except Exception as e:
self._state = EnvironmentResponse(
environment_id=new_environment_id,
environment_id=environment_id,
initialized=False,
error_message=str(e),
)
LOGGER.exception(e)

@start_as_current_span(TRACER)
def stop(self):
existing_environment_id = self._state.environment_id
environment_id = self._state.environment_id
try:
self.run(teardown)
if self._subprocess is not None:
self._subprocess.close()
self._subprocess.join()
self._state = EnvironmentResponse(
environment_id=existing_environment_id,
environment_id=environment_id,
initialized=False,
error_message=self._state.error_message,
)
except Exception as e:
self._state = EnvironmentResponse(
environment_id=existing_environment_id,
environment_id=environment_id,
initialized=False,
error_message=str(e),
)
Expand Down
4 changes: 3 additions & 1 deletion tests/system_tests/test_blueapi_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,5 +338,7 @@ def test_get_current_state_of_environment(client: BlueapiClient):


def test_delete_current_environment(client: BlueapiClient):
current_env = client.get_environment()
client.reload_environment()
assert client.get_environment().initialized
new_env = client.get_environment()
assert new_env.initialized and new_env != current_env
4 changes: 3 additions & 1 deletion tests/unit_tests/client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def mock_rest() -> BlueapiRestClient:
mock.get_all_tasks.return_value = TASKS
mock.get_active_task.return_value = ACTIVE_TASK
mock.get_environment.return_value = ENV
mock.delete_environment.return_value = ENV
mock.delete_environment.return_value = EnvironmentResponse(
environment_id=ENVIRONMENT_ID, initialized=False
)
return mock


Expand Down

0 comments on commit 92f5800

Please sign in to comment.