upower/150.patch
Benjamin Berg 32c353f8f5 Update to 0.99.19
Resolves: #2050327
Resolves: #2093607
2022-06-09 18:42:23 +02:00

68 lines
3.1 KiB
Diff

From a78ee6039054770b466749f8ec4bfbe4c278d697 Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Thu, 9 Jun 2022 12:38:34 +0200
Subject: [PATCH] test: Properly wait for idle handler after uevents
The state aggregation test requires an idle handler to run, which can be
a bit unreliable as it may or may not run twice.
Force running it twice and add code to wait for it to complete. Do so
properly by waiting for the correct log messages rather than sleeping so
that everything is ordered nicely while not slowing down the test a lot.
Closes: #193
---
src/linux/integration-test.py | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/src/linux/integration-test.py b/src/linux/integration-test.py
index d60453e..9523f28 100755
--- a/src/linux/integration-test.py
+++ b/src/linux/integration-test.py
@@ -649,6 +649,8 @@ class Tests(dbusmock.DBusTestCase):
(TBD , CHARGING , DISCHARGING, TBD , TBD , P_CHARGE , ANY),
(ANY , CHARGING , DISCHARGING, ANY , ANY , ANY , ANY),
]
+
+ self.daemon_log.clear()
for i in range(len(states)):
for j in range(len(states)):
# The table should be mirrored
@@ -657,9 +659,19 @@ class Tests(dbusmock.DBusTestCase):
self.testbed.set_attribute(bat0, 'status', states[i])
self.testbed.set_attribute(bat1, 'status', states[j])
self.testbed.uevent(bat0, 'change')
+ # We can't guarantee that both uevents are processed without
+ # the idle handler running. So, lets wait for the idle handler
+ # to calculate the composite battery state.
+ self.daemon_log.check_line('Calculating percentage', timeout=2.0)
self.testbed.uevent(bat1, 'change')
- # The uevent can race with the DBus request
- time.sleep(0.5)
+
+ if display_device_state[i][j] == CONFLICT:
+ self.daemon_log.check_line_re("Conflicting.*state", timeout=2.0)
+ else:
+ # TODO: Add a helper in OutputChecker to do this
+ lines = self.daemon_log.check_line('Calculating percentage', timeout=2.0)
+ for l in lines:
+ self.assertNotRegex(l, b"Conflicting.*state")
if display_device_state[i][j] >= 0:
self.assertEqual(self.get_dbus_display_property('State'), display_device_state[i][j],
@@ -675,10 +687,7 @@ class Tests(dbusmock.DBusTestCase):
UP_DEVICE_STATE_PENDING_DISCHARGE),
msg=f"Invalid aggregate state for states {states[i]} and {states[j]}"
)
- if display_device_state[i][j] == CONFLICT:
- self.daemon_log.check_line_re("Conflicting.*state")
- else:
- self.daemon_log.check_no_line_re("Conflicting.*state")
+
self.stop_daemon()
def test_map_pending_charge_to_fully_charged(self):
--
GitLab