Skip to content

Commit

Permalink
fix: Python API fix tasks service
Browse files Browse the repository at this point in the history
  • Loading branch information
qdelamea-aneo committed Jan 5, 2024
1 parent f28a123 commit a5117c8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 49 deletions.
32 changes: 21 additions & 11 deletions packages/csharp/ArmoniK.Api.Mock/Services/Tasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Collections.Generic;
using System.Threading.Tasks;

using ArmoniK.Api.gRPC.V1;
Expand Down Expand Up @@ -67,8 +68,8 @@ public override Task<ListTasksResponse> ListTasks(ListTasksRequest request,
ServerCallContext context)
=> Task.FromResult(new ListTasksResponse
{
Page = 0,
Total = 0,
Page = 1,
Total = 1,
PageSize = request.PageSize,
});

Expand All @@ -87,19 +88,28 @@ public override Task<CancelTasksResponse> CancelTasks(CancelTasksRequest request
/// <inheritdocs />
[Count]
public override Task<CountTasksByStatusResponse> CountTasksByStatus(CountTasksByStatusRequest request,
ServerCallContext context)
=> Task.FromResult(new CountTasksByStatusResponse());
ServerCallContext context)
{
var result = new CountTasksByStatusResponse();
result.Status.Add(new StatusCount{Status=TaskStatus.Completed, Count=2});
result.Status.Add(new StatusCount{Status=TaskStatus.Submitted, Count=5});
return Task.FromResult(result);
}

/// <inheritdocs />
[Count]
public override Task<ListTasksDetailedResponse> ListTasksDetailed(ListTasksRequest request,
public override Task<ListTasksDetailedResponse> ListTasksDetailed(ListTasksRequest request,
ServerCallContext context)
=> Task.FromResult(new ListTasksDetailedResponse
{
Page = 0,
Total = 0,
PageSize = request.PageSize,
});
{
var result = new ListTasksDetailedResponse
{
Page = 0,
Total = 1,
PageSize = request.PageSize,
};
result.Tasks.Add(MockTask);
return Task.FromResult(result);
}

/// <inheritdocs />
[Count]
Expand Down
7 changes: 2 additions & 5 deletions packages/python/src/armonik/common/enumwrapper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations
from enum import IntEnum

from ..protogen.common.task_status_pb2 import TaskStatus as RawStatus, _TASKSTATUS, TASK_STATUS_CANCELLED, TASK_STATUS_CANCELLING, TASK_STATUS_COMPLETED, TASK_STATUS_CREATING, TASK_STATUS_DISPATCHED, TASK_STATUS_ERROR, TASK_STATUS_PROCESSED, TASK_STATUS_PROCESSING, TASK_STATUS_SUBMITTED, TASK_STATUS_TIMEOUT, TASK_STATUS_UNSPECIFIED, TASK_STATUS_RETRIED
from ..protogen.common.events_common_pb2 import EventsEnum as rawEventsEnum, EVENTS_ENUM_UNSPECIFIED, EVENTS_ENUM_NEW_TASK, EVENTS_ENUM_TASK_STATUS_UPDATE, EVENTS_ENUM_NEW_RESULT, EVENTS_ENUM_RESULT_STATUS_UPDATE, EVENTS_ENUM_RESULT_OWNER_UPDATE
Expand All @@ -17,11 +18,7 @@ class HealthCheckStatus:
UNKNOWN = HealthCheckReply.UNKNOWN


class TaskStatus:
@staticmethod
def name_from_value(status: RawStatus) -> str:
return _TASKSTATUS.values_by_number[status].name

class TaskStatus(IntEnum):
CANCELLED = TASK_STATUS_CANCELLED
CANCELLING = TASK_STATUS_CANCELLING
COMPLETED = TASK_STATUS_COMPLETED
Expand Down
71 changes: 38 additions & 33 deletions packages/python/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,18 @@


class TestArmoniKTasks:

def test_get_task(self):
tasks_client: ArmoniKTasks = get_client("Tasks")
task = tasks_client.get_task("task-id")

assert rpc_called("Tasks", "GetTask")
assert isinstance(task, Task)
assert task.id == 'task-id'
assert task.session_id == 'session-id'
assert task.data_dependencies == []
assert task.expected_output_ids == []
assert task.retry_of_ids == []
assert task.status == TaskStatus.COMPLETED
assert task.payload_id is None
assert task.status_message == ''
assert task.options == TaskOptions(
mock_task = Task(
id='task-id',
session_id='session-id',
owner_pod_id='',
parent_task_ids=[],
data_dependencies=[],
expected_output_ids=[],
retry_of_ids=[],
status=4,
payload_id=None,
status_message='',
options=TaskOptions(
max_duration=datetime.timedelta(seconds=1),
priority=1,
max_retries=1,
Expand All @@ -32,39 +28,48 @@ def test_get_task(self):
application_service='application-service',
engine_type='engine-type',
options={}
)
assert task.created_at == datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)
assert task.submitted_at == datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)
assert task.started_at == datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)
assert task.ended_at == datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)
assert task.pod_ttl == datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)
assert task.output == Output(error='')
assert task.pod_hostname == ''
assert task.received_at == datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)
assert task.acquired_at == datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)
),
created_at=datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc),
submitted_at=datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc),
started_at=datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc),
ended_at=datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc),
pod_ttl=datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc),
output=Output(error=''),
pod_hostname='',
received_at=datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc),
acquired_at=datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)
)

def test_get_task(self):
tasks_client: ArmoniKTasks = get_client("Tasks")
task = tasks_client.get_task("task-id")

assert rpc_called("Tasks", "GetTask")
assert isinstance(task, Task)
assert task == self.mock_task

def test_list_tasks_detailed_no_filter(self):
tasks_client: ArmoniKTasks = get_client("Tasks")
num, tasks = tasks_client.list_tasks()
assert rpc_called("Tasks", "ListTasksDetailed")
# TODO: Mock must be updated to return something and so that changes the following assertions
assert num == 0
assert tasks == []
assert num == 1
assert tasks == [self.mock_task]

def test_list_tasks_detailed_with_filter(self):
tasks_client: ArmoniKTasks = get_client("Tasks")
num, tasks = tasks_client.list_tasks(TaskFieldFilter.STATUS == TaskStatus.COMPLETED)
assert rpc_called("Tasks", "ListTasksDetailed", 2)
# TODO: Mock must be updated to return something and so that changes the following assertions
assert num == 0
assert tasks == []
assert num == 1
assert tasks == [self.mock_task]

def test_list_tasks_no_detailed_no_filter(self):
tasks_client: ArmoniKTasks = get_client("Tasks")
num, tasks = tasks_client.list_tasks(detailed=False)
assert rpc_called("Tasks", "ListTasks")
# TODO: Mock must be updated to return something and so that changes the following assertions
assert num == 0
assert num == 1
assert tasks == []

def test_cancel_tasks(self):
Expand All @@ -86,14 +91,14 @@ def test_count_tasks_by_status_no_filter(self):
count = tasks_client.count_tasks_by_status()
assert rpc_called("Tasks", "CountTasksByStatus")
# TODO: Mock must be updated to return something and so that changes the following assertions
assert count == {}
assert count == {TaskStatus.COMPLETED: 2, TaskStatus.SUBMITTED: 5}

def test_count_tasks_by_status_with_filter(self):
tasks_client: ArmoniKTasks = get_client("Tasks")
count = tasks_client.count_tasks_by_status(TaskFieldFilter.STATUS == TaskStatus.COMPLETED)
assert rpc_called("Tasks", "CountTasksByStatus", 2)
# TODO: Mock must be updated to return something and so that changes the following assertions
assert count == {}
assert count == {TaskStatus.COMPLETED: 2, TaskStatus.SUBMITTED: 5}

def test_submit_tasks(self):
tasks_client: ArmoniKTasks = get_client("Tasks")
Expand Down

0 comments on commit a5117c8

Please sign in to comment.