Skip to content

Commit

Permalink
Fix restarting an asynchronous study (#519)
Browse files Browse the repository at this point in the history
  • Loading branch information
deleon117 authored Sep 18, 2024
1 parent 18cc2ac commit c1d919b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "flit_core.buildapi"
[project]
# Check https://flit.readthedocs.io/en/latest/pyproject_toml.html for all available sections
name = "ansys-additive-core"
version = "0.19.dev24"
version = "0.19.dev25"
description = "A Python client for the Ansys Additive service"
readme = "README.rst"
requires-python = ">=3.10,<4"
Expand Down
10 changes: 7 additions & 3 deletions src/ansys/additive/core/simulation_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ def __init__(
self._simulation_input = simulation_input
self._summary = None

@property
def simulation_id(self) -> str:
"""Get the simulation id associated with this task."""
return self._simulation_input.id

@property
def summary(
self,
Expand Down Expand Up @@ -117,9 +122,8 @@ def status(self) -> Progress:
Progress
The progress of the operation.
"""
if not self._long_running_op.done:
get_request = GetOperationRequest(name=self._long_running_op.name)
self._long_running_op = self._server.operations_stub.GetOperation(get_request)
get_request = GetOperationRequest(name=self._long_running_op.name)
self._long_running_op = self._server.operations_stub.GetOperation(get_request)
progress = self._update_operation_status(self._long_running_op)
return progress

Expand Down
5 changes: 5 additions & 0 deletions src/ansys/additive/core/simulation_task_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def tasks(self) -> list[SimulationTask]:
"""Get the list of tasks managed by this manager."""
return self._tasks

@property
def simulation_ids(self) -> list[str]:
"""Get the list of the simulation ids managed by this manager."""
return [x.simulation_id for x in self._tasks]

@property
def done(self) -> bool:
"""Check if all tasks are done."""
Expand Down
11 changes: 11 additions & 0 deletions tests/test_simulation_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,14 @@ def test_wait_calls_update_progress_and_break_with_completed_operations(
# assert
# Note: status is updated twice within wait().
assert update_mock.call_count == 2


@patch("ansys.additive.core.additive.ServerConnection")
def test_simulation_id_property_returns_id_from_input(mock_server, tmp_path: pathlib.Path):
# arrange
sim_input = SingleBeadInput()

task = SimulationTask(mock_server, Operation(name="some_other_name"), sim_input, tmp_path)

# act & assert
assert task.simulation_id == sim_input.id
20 changes: 19 additions & 1 deletion tests/test_simulation_task_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from unittest.mock import Mock
from unittest.mock import Mock, PropertyMock

from ansys.additive.core.progress_handler import Progress, ProgressState
from ansys.additive.core.simulation_task_manager import SimulationTask, SimulationTaskManager
Expand Down Expand Up @@ -105,3 +105,21 @@ def test_cancel_all_calls_each_task_cancel():
# assert
mock_task1.cancel.assert_called_once()
mock_task2.cancel.assert_called_once()


def test_simulation_ids():
# arrange
mock_task1 = Mock(SimulationTask)
mock_task2 = Mock(SimulationTask)
type(mock_task1).simulation_id = PropertyMock(return_value="sim1")
type(mock_task2).simulation_id = PropertyMock(return_value="sim2")

taskMgr = SimulationTaskManager()
taskMgr.add_task(mock_task1)
taskMgr.add_task(mock_task2)

# act
sim_ids = taskMgr.simulation_ids

# assert
assert sim_ids == ["sim1", "sim2"]

0 comments on commit c1d919b

Please sign in to comment.