Skip to content

Commit

Permalink
Fixed minor error in Heartbeat logic
Browse files Browse the repository at this point in the history
  • Loading branch information
eandersson committed Apr 22, 2017
1 parent 41dad6e commit e0cb97a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion amqpstorm/heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _check_for_life_signs(self):
if self._reads_since_check == 0:
self._threshold += 1
if self._threshold >= 2:
self._running.set()
self._running.clear()
message = (
'Connection dead, no heartbeat or data received in >= '
'%ds' % (
Expand Down
16 changes: 16 additions & 0 deletions amqpstorm/tests/unit/heartbeat_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,22 @@ def test_heartbeat_raise_after_threshold(self):

heartbeat.stop()

def test_heartbeat_running_cleared_after_raise(self):
heartbeat = Heartbeat(60, fake_function)
exceptions = []
heartbeat.start(exceptions)

self.assertTrue(heartbeat._running.is_set())

heartbeat.register_write()
heartbeat._check_for_life_signs()
heartbeat.register_write()
heartbeat._check_for_life_signs()

self.assertFalse(heartbeat._running.is_set())

heartbeat.stop()

def test_heartbeat_raise_when_check_for_life_when_exceptions_not_set(self):
heartbeat = Heartbeat(60, fake_function)
heartbeat._running.set()
Expand Down

0 comments on commit e0cb97a

Please sign in to comment.