Island, UT: fix a bug in "is monkey killed" endpoint

The bug happened because by default there's no kill event so kill event time is None
This commit is contained in:
vakarisz 2021-12-09 18:17:35 +02:00 committed by Mike Salvatore
parent 1c76ea20f2
commit 8d325df6d6
2 changed files with 11 additions and 1 deletions

View File

@ -33,11 +33,13 @@ def _is_monkey_marked_dead(monkey: Monkey) -> bool:
def _is_monkey_killed_manually(monkey: Monkey) -> bool:
kill_timestamp = AgentControls.objects.first().last_stop_all
if kill_timestamp is None:
return False
if monkey.has_parent():
launch_timestamp = monkey.get_parent().launch_time
else:
launch_timestamp = monkey.launch_time
kill_timestamp = AgentControls.objects.first().last_stop_all
return int(kill_timestamp) >= int(launch_timestamp)

View File

@ -30,6 +30,14 @@ def create_monkey(launch_time):
return monkey
@pytest.mark.usefixtures("uses_database")
def test_should_agent_die_no_kill_event():
monkey = create_monkey(launch_time=3)
kill_event = AgentControls()
kill_event.save()
assert not should_agent_die(monkey.guid)
def create_kill_event(event_time):
kill_event = AgentControls(last_stop_all=event_time)
kill_event.save()