Bug 1335778 - Harden test_page_timeout_fail against intermittent failures. draft
authorHenrik Skupin <mail@hskupin.info>
Thu, 13 Apr 2017 14:57:25 +0200
changeset 568548 bf1ee74d77455e3bb8d6c002fddc44ff18990a74
parent 568547 1016c179421984746d72d4abce5395365ed1a302
child 568549 0b0c47578eaf34aaa0e966d353ad8eb4e7b173de
child 568741 c1fbe19de9c0b337293cd665f47aa9cf014c8767
child 568878 056f388a5d74695c7e0105e65bb893ac438ec09c
push id55897
push userbmo:hskupin@gmail.com
push dateWed, 26 Apr 2017 09:17:50 +0000
bugs1335778
milestone55.0a1
Bug 1335778 - Harden test_page_timeout_fail against intermittent failures. Tests for page timeout durations have to use an HTTPD handler that delays or slows down document load. Otherwise there a risk that the timeout error is not returned before the document finishes loading. MozReview-Commit-ID: HGGcXfCuaSH
testing/marionette/harness/marionette_harness/tests/unit/test_timeouts.py
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_timeouts.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_timeouts.py
@@ -19,31 +19,34 @@ class TestTimeouts(MarionetteTestCase):
         MarionetteTestCase.tearDown(self)
 
     def test_page_timeout_notdefinetimeout_pass(self):
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
 
     def test_page_timeout_fail(self):
         self.marionette.timeout.page_load = 0
-        test_html = self.marionette.absolute_url("test.html")
-        self.assertRaises(MarionetteException, self.marionette.navigate, test_html)
+        test_html = self.marionette.absolute_url("slow")
+        with self.assertRaises(MarionetteException):
+            self.marionette.navigate(test_html)
 
     def test_page_timeout_pass(self):
         self.marionette.timeout.page_load = 60
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
 
     def test_search_timeout_notfound_settimeout(self):
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
         self.marionette.timeout.implicit = 1
-        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "I'm not on the page")
+        with self.assertRaises(NoSuchElementException):
+            self.marionette.find_element(By.ID, "I'm not on the page")
         self.marionette.timeout.implicit = 0
-        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "I'm not on the page")
+        with self.assertRaises(NoSuchElementException):
+            self.marionette.find_element(By.ID, "I'm not on the page")
 
     @skip_if_mobile("Bug 1317121 - android emulator is too slow")
     def test_search_timeout_found_settimeout(self):
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
         button = self.marionette.find_element(By.ID, "createDivButton")
         button.click()
         self.marionette.timeout.implicit = 8
@@ -77,17 +80,18 @@ class TestTimeouts(MarionetteTestCase):
 
         do_check(self.marionette.restart)
         do_check(callback_quit)
 
     def test_execute_async_timeout_settimeout(self):
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
         self.marionette.timeout.script = 1
-        self.assertRaises(ScriptTimeoutException, self.marionette.execute_async_script, "var x = 1;")
+        with self.assertRaises(ScriptTimeoutException):
+            self.marionette.execute_async_script("var x = 1;")
 
     def test_no_timeout_settimeout(self):
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
         self.marionette.timeout.script = 1
         self.assertTrue(self.marionette.execute_async_script("""
              var callback = arguments[arguments.length - 1];
              setTimeout(function() { callback(true); }, 500);