Commit Graph

15 Commits

Author SHA1 Message Date
Philip Withnall
67a9fbf1fa tests: Wait for memory monitor to be able to handle signals before testing
This fixes a race condition which frequently caused the
`memory-monitor-dbus.py` test to fail.

The registration of the `LowMemoryMonitor` object on the bus, and the
`GMemoryMonitorDBus`’s connection to the warning signal raced, such that
it was possible for the mock `LowMemoryMonitor` to emit a warning signal
before the `GMemoryMonitorDBus` proxy was listening, and hence the proxy
would never see the signal.

Fix this by explicitly synchronising the two before proceeding to the
tests.

Make the same changes in the `memory-monitor-portal.py` test too, even
though that one was not failing. This should remove the need for a 2s
wait on every test run.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Fixes: #2887
2024-01-23 11:02:48 +00:00
Philip Withnall
e0276a3a17 tests: Wait for LMM server to be available when starting test
Otherwise the test can go on to wait for a signal from the service
before it’s actually finished starting up.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #2887
2024-01-23 11:02:48 +00:00
Philip Withnall
6b22aaaa68 tests: Assert correct monitor implementation is used in memory-monitor-dbus
This wasn’t failing, but it seems like a sensible thing to check.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #2887
2024-01-23 11:02:48 +00:00
Philip Withnall
e3b81b3f0d tests: Rework assertEventually() to use GLib main context
Rather than sleeping and blocking everything, use a timeout source on
the main context so that inputs can continue to be handled while waiting
for a timeout.

This introduces no functional changes to the test.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #2887
2024-01-23 11:02:48 +00:00
Philip Withnall
8a4ad5f998 tests: Add some debug output to memory-monitor-dbus.py test
This will hopefully help diagnose #2887.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #2887
2024-01-22 11:22:45 +00:00
Philip Withnall
5278efbd63 tests: Ensure Python assertEventually() function uses correct main context
It should be doing already (or the tests would never work), but make it
clearer in the code that the same `GMainContext` is being iterated as is
being woken up in the rest of the test.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #2887
2024-01-22 11:22:01 +00:00
Bastien Nocera
e1819c42fb gio: Fix conditions in memory-monitor test
We were lucky that this worked in some cases (the test is racy), but we
should actually run the condition check each loop, rather than when the
function is called.

Spotted by Martin Pitt:
96a8c02d24 (r54773831)
2021-09-06 14:46:15 +02:00
Bastien Nocera
2e9842cafc gio: Simplify memory monitor tests by using assertEventually() helper
assertEventually is a helper used in a number of projects that use
dbusmock.

See https://github.com/martinpitt/python-dbusmock/issues/82
2021-08-13 01:32:31 +02:00
Bastien Nocera
2e500304e3 tests: Remove unused constant in GMemoryMonitor test 2021-07-28 15:04:46 +02:00
Ross Burton
2709d5e1bb gio/tests/memory-monitor-*.py.in: skip if 3rd party modules not available
The GIO tests memory-monitor-dbus and memory-monitor-portal use a number
of third party Python modules that may not be present when running the
test case.

Instead of failing due to missing imports, catch the ImportError and
mock a test case that skips.  This can't use the usual unittest.skip
logic because the test case class itself uses a 3rd party module.

Closes #2083.
2020-04-23 15:01:25 +01:00
Ross Burton
1fcd32a159 gio: use TAPTestRunner in the memory monitor tests
There are two memory monitor tests that use Python's unittest module directly,
but GLib tests should be outputting TAP.  Use the embedded TAPTestRunner to
ensure that TAP is output for these tests too.
2020-04-09 14:55:39 +01:00
Simon McVittie
fdbd9ed7f7 tests: Skip MemoryMonitor test if GObject-Introspection is too old
Distributions will likely want to update GLib before
GObject-Introspection, to avoid circular dependencies.

Signed-off-by: Simon McVittie <smcv@debian.org>
2020-02-28 12:42:36 +00:00
Bastien Nocera
b7586da9bf 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.
2020-02-04 17:28:07 +01:00
Iain Lane
0d4f1a9b21
tests: Skip GMemoryMonitor tests if the dbusmock template is not available
This template is not currently in any released version of dbusmock.
2020-01-22 07:41:17 +00:00
Bastien Nocera
8e8ee82580 tests: Add GMemoryMonitor installed-tests
Those tests require Python, gobject-introspection and python-dbusmock
making them unsuitable to be run within the uninstalled test suite.

There are no restrictions of dependencies when it comes to installed
tests so use those to exercise GMemoryMonitor.
2019-12-11 11:44:42 +00:00