tests: Fix timeouts not working in GMemoryMonitor tests

The loops should continue iterating if the timeout is non-zero and we're
still waiting for the updated value. Otherwise, if things break, we'll
be waiting until we receive a value that never arrives.
This commit is contained in:
Bastien Nocera 2020-01-27 21:40:51 +01:00
parent 4fe2c7ffdb
commit b7586da9bf
2 changed files with 4 additions and 4 deletions

View File

@ -75,7 +75,7 @@ class TestLowMemoryMonitor(dbusmock.DBusTestCase):
self.dbusmock.EmitWarning(100)
# Wait 2 seconds or until warning
timeout = 2
while timeout > 0 or self.last_warning != 100:
while timeout > 0 and self.last_warning != 100:
time.sleep(0.5)
timeout -= 0.5
self.main_context.iteration(False)
@ -84,7 +84,7 @@ class TestLowMemoryMonitor(dbusmock.DBusTestCase):
self.dbusmock.EmitWarning(255)
# Wait 2 seconds or until warning
timeout = 2
while timeout > 0 or self.last_warning != 255:
while timeout > 0 and self.last_warning != 255:
time.sleep(0.5)
timeout -= 0.5
self.main_context.iteration(False)

View File

@ -91,7 +91,7 @@ class TestLowMemoryMonitorPortal(dbusmock.DBusTestCase):
self.dbusmock.EmitWarning(100)
# Wait 2 seconds or until warning
timeout = 2
while timeout > 0 or self.last_warning != 100:
while timeout > 0 and self.last_warning != 100:
time.sleep(0.5)
timeout -= 0.5
self.main_context.iteration(False)
@ -100,7 +100,7 @@ class TestLowMemoryMonitorPortal(dbusmock.DBusTestCase):
self.dbusmock.EmitWarning(255)
# Wait 2 seconds or until warning
timeout = 2
while timeout > 0 or self.last_warning != 255:
while timeout > 0 and self.last_warning != 255:
time.sleep(0.5)
timeout -= 0.5
self.main_context.iteration(False)