Skip to content

Commit

Permalink
Test timedelta for downtime being 0
Browse files Browse the repository at this point in the history
  • Loading branch information
stveit committed Aug 29, 2024
1 parent 7f04e74 commit 2128133
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/events_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,25 @@ def test_record_downtime_should_not_update_event_if_lasttrans_is_not_set(self):

assert new_event.lasttrans is None
assert new_event.ac_down is None

def test_record_downtime_should_not_update_event_if_downtime_is_calculated_to_zero_or_less(self, monkeypatch):
events = Events()
old_event = events.get_or_create_event("foobar", None, ReachabilityEvent)
old_event.reachability = ReachabilityState.NORESPONSE
events.commit(old_event)

# Make now() return same value as lasttrans so record_downtime
# calculates a timedelta of 0
lasttrans = now()
mocked_now = Mock(return_value=lasttrans)
monkeypatch.setattr("zino.events.now", mocked_now)

new_event = events.checkout(old_event.id)
new_event.reachability = ReachabilityState.REACHABLE
new_event.lasttrans = lasttrans
new_event.ac_down = None

events.record_downtime(new_event, old_event)

assert new_event.lasttrans == lasttrans
assert new_event.ac_down is None

0 comments on commit 2128133

Please sign in to comment.