summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2023-01-17 16:51:53 +0100
committerBastien Nocera <hadess@hadess.net>2023-01-18 10:48:13 +0100
commite80d952335c9e64dc55e0a27920b106869b0ed05 (patch)
treefa97ae8ecdb2663313ddf349b9d40a4c33d1a509
parent4e3aba5a43e1e59bae1c4503b55fe2ab3af2ebb8 (diff)
downloadglib-e80d952335c9e64dc55e0a27920b106869b0ed05.tar.gz
gio: Better debug in memory-monitor tests
-rwxr-xr-xgio/tests/memory-monitor-dbus.py.in19
-rwxr-xr-xgio/tests/memory-monitor-portal.py.in19
2 files changed, 18 insertions, 20 deletions
diff --git a/gio/tests/memory-monitor-dbus.py.in b/gio/tests/memory-monitor-dbus.py.in
index bf3291847..acbc576ca 100755
--- a/gio/tests/memory-monitor-dbus.py.in
+++ b/gio/tests/memory-monitor-dbus.py.in
@@ -66,22 +66,21 @@ try:
self.p_mock.terminate()
self.p_mock.wait()
- def assertEventually(self, condition, message=None, timeout=50):
- '''Assert that condition function eventually returns True.
+ def assertLevelEventually(self, expected_level, timeout=50):
+ '''Assert that the expected level is eventually reached.
- Timeout is in deciseconds, defaulting to 50 (5 seconds). message is
- printed on failure.
+ Timeout is in deciseconds, defaulting to 50 (5 seconds).
'''
while timeout >= 0:
context = GLib.MainContext.default()
while context.iteration(False):
pass
- if condition():
+ if self.last_warning == expected_level:
break
timeout -= 1
time.sleep(0.1)
else:
- self.fail(message or 'timed out waiting for ' + str(condition))
+ self.fail(f'timed out waiting for expected level {expected_level}, last warning is {self.last_warning}')
def memory_warning_cb(self, monitor, level):
self.last_warning = level
@@ -98,12 +97,12 @@ try:
self.main_context.iteration(False)
self.dbusmock.EmitWarning(100)
- # Wait 2 seconds or until warning
- self.assertEventually(lambda: self.last_warning == 100, "'100' low-memory warning not received", 20)
+ # Wait 5 seconds or until warning
+ self.assertLevelEventually(100)
self.dbusmock.EmitWarning(255)
- # Wait 2 seconds or until warning
- self.assertEventually(lambda: self.last_warning == 255, "'255' low-memory warning not received", 20)
+ # Wait 5 seconds or until warning
+ self.assertLevelEventually(255)
except ImportError as e:
@unittest.skip("Cannot import %s" % e.name)
diff --git a/gio/tests/memory-monitor-portal.py.in b/gio/tests/memory-monitor-portal.py.in
index 748cee850..d06fad297 100755
--- a/gio/tests/memory-monitor-portal.py.in
+++ b/gio/tests/memory-monitor-portal.py.in
@@ -84,22 +84,21 @@ try:
self.p_mock.terminate()
self.p_mock.wait()
- def assertEventually(self, condition, message=None, timeout=50):
- '''Assert that condition function eventually returns True.
+ def assertLevelEventually(self, expected_level, timeout=50):
+ '''Assert that the expected level is eventually reached.
- Timeout is in deciseconds, defaulting to 50 (5 seconds). message is
- printed on failure.
+ Timeout is in deciseconds, defaulting to 50 (5 seconds).
'''
while timeout >= 0:
context = GLib.MainContext.default()
while context.iteration(False):
pass
- if condition():
+ if self.last_warning == expected_level:
break
timeout -= 1
time.sleep(0.1)
else:
- self.fail(message or 'timed out waiting for ' + str(condition))
+ self.fail(f'timed out waiting for expected level {expected_level}, last warning is {self.last_warning}')
def portal_memory_warning_cb(self, monitor, level):
self.last_warning = level
@@ -116,12 +115,12 @@ try:
self.main_context.iteration(False)
self.dbusmock.EmitWarning(100)
- # Wait 2 seconds or until warning
- self.assertEventually(lambda: self.last_warning == 100, "'100' low-memory warning not received", 20)
+ # Wait 5 seconds or until warning
+ self.assertLevelEventually(100)
self.dbusmock.EmitWarning(255)
- # Wait 2 seconds or until warning
- self.assertEventually(lambda: self.last_warning == 255, "'255' low-memory warning not received", 20)
+ # Wait 5 seconds or until warning
+ self.assertLevelEventually(255)
except ImportError as e:
@unittest.skip("Cannot import %s" % e.name)