Bug 1488468 - Filter ping_list in Wait function of TelemetryTestCase; r=davehunt
authorRaphael Pierzina <rpierzina@mozilla.com>
Tue, 16 Oct 2018 08:28:56 +0000
changeset 489793 bf88501c1f8af00508f0a13029329ea2f005f51c
parent 489792 0f0249190e74309e4de3a16e9b15400e39ce518e
child 489794 51b87be56bcae1931f2a8b76b2494c945c3b2db8
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersdavehunt
bugs1488468
milestone64.0a1
Bug 1488468 - Filter ping_list in Wait function of TelemetryTestCase; r=davehunt Differential Revision: https://phabricator.services.mozilla.com/D8531
toolkit/components/telemetry/tests/marionette/harness/telemetry_harness/testcase.py
--- a/toolkit/components/telemetry/tests/marionette/harness/telemetry_harness/testcase.py
+++ b/toolkit/components/telemetry/tests/marionette/harness/telemetry_harness/testcase.py
@@ -46,25 +46,33 @@ class TelemetryTestCase(PuppeteerMixin, 
 
         # Firefox will be forced to restart with the prefs enforced.
         self.marionette.enforce_gecko_prefs(telemetry_prefs)
 
         # Wait 5 seconds to ensure that telemetry has reinitialized
         time.sleep(5)
 
     def wait_for_ping(self, action_func, ping_filter_func):
+        # Filter pings initially using `ping_filter_func`
+        self.ping_list = [p for p in self.ping_list if ping_filter_func(p)]
+
         current_num_pings = len(self.ping_list)
+
         if callable(action_func):
             action_func()
+
+        def wait_func(*args, **kwargs):
+            # Filter pings based on type and reason to make sure right ping is captured.
+            self.ping_list = [p for p in self.ping_list if ping_filter_func(p)]
+            return len(self.ping_list) > current_num_pings
+
         try:
-            Wait(self.marionette, 60).until(lambda _: len(self.ping_list) > current_num_pings)
+            Wait(self.marionette, 60).until(wait_func)
         except Exception as e:
             self.fail('Error generating ping: {}'.format(e.message))
-        # Filter pings based on type and reason to make sure right ping is captured.
-        self.ping_list = [p for p in self.ping_list if ping_filter_func(p)]
 
         # TODO: Bug 1380748 - Pings are being cached between test
         # runs when using --repeat flag in marionette harness
         # Causes the assert to fail.
         # assert len(self.ping_list) == 1
         return self.ping_list.pop()
 
     def restart_browser(self):