Skip to content

Commit

Permalink
fixed join logic and added logic to the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TamarZanzouri committed Nov 22, 2024
1 parent e0aacbd commit b10e8a2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
18 changes: 13 additions & 5 deletions robot-server/robot_server/runs/run_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,19 +612,27 @@ def get_commands_errors_slice(

actual_cursor = cursor if cursor is not None else count_result - length
# Clamp to [0, count_result).
print(actual_cursor)
actual_cursor = max(0, min(actual_cursor, count_result - 1))
select_command_errors = (
sqlalchemy.select(run_command_table)
.where(run_command_table.c.command_error is not None)
sqlalchemy.select(sqlalchemy.func.row_number().over().label('row_num'), run_command_table)
.where(
and_(
run_command_table.c.run_id == run_id,
run_command_table.c.command_status == CommandStatusSQLEnum.FAILED
)
)
.subquery()
)
print(transaction.execute(select_command_errors).all())
print(actual_cursor)
print(count_result)
select_slice = (
sqlalchemy.select(run_command_table.c.command_error)
.where(
and_(
run_command_table.c.run_id == run_id,
run_command_table.c.index_in_run >= actual_cursor,
run_command_table.c.index_in_run < actual_cursor + length,
select_command_errors.c.row_num >= actual_cursor,
select_command_errors.c.row_num < actual_cursor + length,
)
)
.join_from(
Expand Down
29 changes: 26 additions & 3 deletions robot-server/tests/runs/test_run_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ def protocol_commands() -> List[pe_commands.Command]:
def protocol_commands_errors() -> List[pe_commands.Command]:
"""Get protocol commands errors list."""
return [
pe_commands.WaitForResume(
id="pause-4",
key="command-key",
status=pe_commands.CommandStatus.SUCCEEDED,
createdAt=datetime(year=2022, month=2, day=2),
params=pe_commands.WaitForResumeParams(message="hey world"),
result=pe_commands.WaitForResumeResult(),
intent=pe_commands.CommandIntent.PROTOCOL,
),
pe_commands.WaitForResume(
id="pause-1",
key="command-key",
Expand Down Expand Up @@ -134,6 +143,15 @@ def protocol_commands_errors() -> List[pe_commands.Command]:
detail="test details",
),
),
pe_commands.WaitForResume(
id="pause-3",
key="command-key",
status=pe_commands.CommandStatus.SUCCEEDED,
createdAt=datetime(year=2022, month=2, day=2),
params=pe_commands.WaitForResumeParams(message="hey world"),
result=pe_commands.WaitForResumeResult(),
intent=pe_commands.CommandIntent.PROTOCOL,
),
]


Expand Down Expand Up @@ -335,6 +353,11 @@ async def test_update_run_state_command_with_errors(
mock_runs_publisher: mock.Mock,
) -> None:
"""It should be able to update a run state to the store."""
commands_with_errors = [
command
for command in protocol_commands_errors
if command.status == pe_commands.CommandStatus.FAILED
]
action = RunAction(
actionType=RunActionType.PLAY,
createdAt=datetime(year=2022, month=2, day=2, tzinfo=timezone.utc),
Expand All @@ -357,14 +380,14 @@ async def test_update_run_state_command_with_errors(
subject.insert_action(run_id="run-id", action=action)
command_errors_result = subject.get_commands_errors_slice(
run_id="run-id",
length=len(protocol_commands_errors),
cursor=0,
length=5,
cursor=2,
)

print(command_errors_result)

assert command_errors_result.commands_errors == [
item.error for item in protocol_commands_errors
item.error for item in commands_with_errors
]


Expand Down

0 comments on commit b10e8a2

Please sign in to comment.