mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-20 23:58:54 +02:00
gio: Better debug in memory-monitor tests
This commit is contained in:
@@ -66,22 +66,21 @@ try:
|
|||||||
self.p_mock.terminate()
|
self.p_mock.terminate()
|
||||||
self.p_mock.wait()
|
self.p_mock.wait()
|
||||||
|
|
||||||
def assertEventually(self, condition, message=None, timeout=50):
|
def assertLevelEventually(self, expected_level, timeout=50):
|
||||||
'''Assert that condition function eventually returns True.
|
'''Assert that the expected level is eventually reached.
|
||||||
|
|
||||||
Timeout is in deciseconds, defaulting to 50 (5 seconds). message is
|
Timeout is in deciseconds, defaulting to 50 (5 seconds).
|
||||||
printed on failure.
|
|
||||||
'''
|
'''
|
||||||
while timeout >= 0:
|
while timeout >= 0:
|
||||||
context = GLib.MainContext.default()
|
context = GLib.MainContext.default()
|
||||||
while context.iteration(False):
|
while context.iteration(False):
|
||||||
pass
|
pass
|
||||||
if condition():
|
if self.last_warning == expected_level:
|
||||||
break
|
break
|
||||||
timeout -= 1
|
timeout -= 1
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
else:
|
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):
|
def memory_warning_cb(self, monitor, level):
|
||||||
self.last_warning = level
|
self.last_warning = level
|
||||||
@@ -98,12 +97,12 @@ try:
|
|||||||
self.main_context.iteration(False)
|
self.main_context.iteration(False)
|
||||||
|
|
||||||
self.dbusmock.EmitWarning(100)
|
self.dbusmock.EmitWarning(100)
|
||||||
# Wait 2 seconds or until warning
|
# Wait 5 seconds or until warning
|
||||||
self.assertEventually(lambda: self.last_warning == 100, "'100' low-memory warning not received", 20)
|
self.assertLevelEventually(100)
|
||||||
|
|
||||||
self.dbusmock.EmitWarning(255)
|
self.dbusmock.EmitWarning(255)
|
||||||
# Wait 2 seconds or until warning
|
# Wait 5 seconds or until warning
|
||||||
self.assertEventually(lambda: self.last_warning == 255, "'255' low-memory warning not received", 20)
|
self.assertLevelEventually(255)
|
||||||
|
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
@unittest.skip("Cannot import %s" % e.name)
|
@unittest.skip("Cannot import %s" % e.name)
|
||||||
|
@@ -84,22 +84,21 @@ try:
|
|||||||
self.p_mock.terminate()
|
self.p_mock.terminate()
|
||||||
self.p_mock.wait()
|
self.p_mock.wait()
|
||||||
|
|
||||||
def assertEventually(self, condition, message=None, timeout=50):
|
def assertLevelEventually(self, expected_level, timeout=50):
|
||||||
'''Assert that condition function eventually returns True.
|
'''Assert that the expected level is eventually reached.
|
||||||
|
|
||||||
Timeout is in deciseconds, defaulting to 50 (5 seconds). message is
|
Timeout is in deciseconds, defaulting to 50 (5 seconds).
|
||||||
printed on failure.
|
|
||||||
'''
|
'''
|
||||||
while timeout >= 0:
|
while timeout >= 0:
|
||||||
context = GLib.MainContext.default()
|
context = GLib.MainContext.default()
|
||||||
while context.iteration(False):
|
while context.iteration(False):
|
||||||
pass
|
pass
|
||||||
if condition():
|
if self.last_warning == expected_level:
|
||||||
break
|
break
|
||||||
timeout -= 1
|
timeout -= 1
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
else:
|
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):
|
def portal_memory_warning_cb(self, monitor, level):
|
||||||
self.last_warning = level
|
self.last_warning = level
|
||||||
@@ -116,12 +115,12 @@ try:
|
|||||||
self.main_context.iteration(False)
|
self.main_context.iteration(False)
|
||||||
|
|
||||||
self.dbusmock.EmitWarning(100)
|
self.dbusmock.EmitWarning(100)
|
||||||
# Wait 2 seconds or until warning
|
# Wait 5 seconds or until warning
|
||||||
self.assertEventually(lambda: self.last_warning == 100, "'100' low-memory warning not received", 20)
|
self.assertLevelEventually(100)
|
||||||
|
|
||||||
self.dbusmock.EmitWarning(255)
|
self.dbusmock.EmitWarning(255)
|
||||||
# Wait 2 seconds or until warning
|
# Wait 5 seconds or until warning
|
||||||
self.assertEventually(lambda: self.last_warning == 255, "'255' low-memory warning not received", 20)
|
self.assertLevelEventually(255)
|
||||||
|
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
@unittest.skip("Cannot import %s" % e.name)
|
@unittest.skip("Cannot import %s" % e.name)
|
||||||
|
Reference in New Issue
Block a user