From 010a3c5ec4e749a48c0af312be0bf3bea7e9e412 Mon Sep 17 00:00:00 2001 From: TheBurchLog <5104941+TheBurchLog@users.noreply.github.com> Date: Thu, 11 Jul 2024 13:38:40 -0400 Subject: [PATCH] allow negative checks --- brewtils/models.py | 2 +- test/models_test.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/brewtils/models.py b/brewtils/models.py index 5c2aa1f6..302e5adb 100644 --- a/brewtils/models.py +++ b/brewtils/models.py @@ -457,7 +457,7 @@ def set_status_heartbeat(self, status, max_history=None): self.heartbeat = datetime.utcnow() self.history.append(StatusHistory(status=copy.deepcopy(status), heartbeat=self.heartbeat)) - if max_history and len(self.history) > max_history: + if max_history and max_history > 0 and len(self.history) > max_history: self.history = self.history[(max_history * -1):] def __str__(self): diff --git a/test/models_test.py b/test/models_test.py index 0946f559..6d3e84f3 100644 --- a/test/models_test.py +++ b/test/models_test.py @@ -735,3 +735,11 @@ def test_history(self): status_info.set_status_heartbeat("RUNNING") assert len(status_info.history) == 10 + + def test_negative_history(self): + status_info = StatusInfo() + + for _ in range(10): + status_info.set_status_heartbeat("RUNNING", max_history=-1) + + assert len(status_info.history) == 10