feat(main): add bounded randomized check-interval jitter across nodes
This commit is contained in:
1 parent
b34ac69ac1
commit
d2fdd5be44
7 files changed
+72
-3
No files matched your search
@@ -50,6 +50,19 @@ class RuntimeSettingsEnforcementTests(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual((), settings.enforcement_sets)
|
||||
|
||||
@patch("config.load_config")
|
||||
def test_check_jitter_pct_loaded_and_clamped(self, load_config_mock):
|
||||
load_config_mock.return_value = {
|
||||
"agent": {
|
||||
"check_jitter_pct": 1.5,
|
||||
}
|
||||
}
|
||||
|
||||
with patch.dict(os.environ, {}, clear=True):
|
||||
settings = load_runtime_settings()
|
||||
|
||||
self.assertEqual(0.90, settings.check_jitter_pct)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,22 @@
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from main import compute_sleep_interval
|
||||
|
||||
|
||||
class MainSleepIntervalTests(unittest.TestCase):
|
||||
@patch("main.random.uniform", return_value=0.0)
|
||||
def test_compute_sleep_interval_no_jitter(self, _uniform):
|
||||
self.assertEqual(600.0, compute_sleep_interval(600, 0.0))
|
||||
|
||||
@patch("main.random.uniform", return_value=0.10)
|
||||
def test_compute_sleep_interval_applies_positive_jitter(self, _uniform):
|
||||
self.assertEqual(660.0, compute_sleep_interval(600, 0.10))
|
||||
|
||||
@patch("main.random.uniform", return_value=-0.90)
|
||||
def test_compute_sleep_interval_enforces_minimum_sleep(self, _uniform):
|
||||
self.assertEqual(1.0, compute_sleep_interval(1, 0.90))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user