mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-01 08:26:03 +00:00
fix: worker warnings and CPU windows do not depend on a wall clock
The job panel warned "Worker unavailable" when the worker's last heartbeat was more than 60 s older than the browser's clock: a browser set two minutes ahead warned about a worker that had just beaten, and one behind hid a worker that had stopped. The server now says whether the worker is gone (worker_gone in the job panel's answer), by the same rule as the Jobs page. A host's CPU graph measured its averaging window with time.time(): a clock set back between two polls gave a negative window. It now uses time.monotonic(), as a VM's usage already does; a sample from before the server restarted is measured over a second again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
parent
25e49c2aa2
commit
e83bdcbd44
9 changed files with 55 additions and 21 deletions
|
|
@ -330,7 +330,7 @@ class CpuPercentTestCase(UnitTestCase):
|
|||
@patch("vrtManager.hostdetails.time")
|
||||
class CpuUsageTestCase(UnitTestCase):
|
||||
def test_since_a_previous_sample_without_waiting(self, clock):
|
||||
clock.time.return_value = 105.0
|
||||
clock.monotonic.return_value = 105.0
|
||||
h = host((130, 70))
|
||||
usage = h.get_cpu_usage(previous=(100, 100, 100.0))
|
||||
clock.sleep.assert_not_called()
|
||||
|
|
@ -338,13 +338,20 @@ class CpuUsageTestCase(UnitTestCase):
|
|||
self.assertEqual(usage, {"usage": 70.0, "sample": (130, 200, 105.0), "window": 5.0})
|
||||
|
||||
def test_over_one_second_without_a_sample(self, clock):
|
||||
clock.time.side_effect = [10.0, 11.0]
|
||||
clock.monotonic.side_effect = [10.0, 11.0]
|
||||
h = host((100, 100), (110, 190))
|
||||
self.assertEqual(h.get_cpu_usage(), {"usage": 90.0, "sample": (110, 300, 11.0), "window": 1.0})
|
||||
clock.sleep.assert_called_once_with(1)
|
||||
|
||||
def test_over_one_second_with_a_sample_from_before_the_panel_restarted(self, clock):
|
||||
clock.monotonic.side_effect = [10.0, 11.0] # the clock restarted with the server
|
||||
h = host((100, 100), (110, 190))
|
||||
usage = h.get_cpu_usage(previous=(50, 50, 500.0))
|
||||
clock.sleep.assert_called_once_with(1)
|
||||
self.assertEqual((usage["usage"], usage["window"]), (90.0, 1.0))
|
||||
|
||||
def test_over_one_second_after_the_host_restarted(self, clock):
|
||||
clock.time.side_effect = [10.0, 11.0]
|
||||
clock.monotonic.side_effect = [10.0, 11.0]
|
||||
h = host((5, 5), (6, 9))
|
||||
usage = h.get_cpu_usage(previous=(1000, 5000, 5.0))
|
||||
clock.sleep.assert_called_once_with(1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue