Bug 1458276 - Use correct timeout for RDP connection; r=me
authorJim Chen <nchen@mozilla.com>
Fri, 04 May 2018 11:46:37 -0400
changeset 473029 b758d18e45a581300c993fd738077772f7d5a498
parent 473028 cbdef048e40cdc00eee6079f3761a9c8bd21e60b
child 473030 5e42fccea4f3cd91f90744629a734e440cc44567
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
bugs1458276
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1458276 - Use correct timeout for RDP connection; r=me
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoSessionTestRuleTest.kt
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoSessionTestRuleTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoSessionTestRuleTest.kt
@@ -16,17 +16,16 @@ import org.mozilla.geckoview.test.rule.G
 import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.WithDisplay
 import org.mozilla.geckoview.test.util.Callbacks
 
 import android.support.test.filters.MediumTest
 import android.support.test.runner.AndroidJUnit4
 
 import org.hamcrest.Matchers.*
 import org.junit.Assume.assumeThat
-import org.junit.Ignore
 import org.junit.Test
 import org.junit.runner.RunWith
 
 /**
  * Test for the GeckoSessionTestRule class, to ensure it properly sets up a session for
  * each test, and to ensure it can properly wait for and assert delegate
  * callbacks.
  */
@@ -1174,17 +1173,16 @@ class GeckoSessionTestRuleTest : BaseSes
         sessionRule.session.loadTestPath(CLICK_TO_RELOAD_HTML_PATH)
         sessionRule.session.waitForPageStop()
 
         sessionRule.session.synthesizeTap(5, 5)
         sessionRule.session.waitForPageStop()
     }
 
     @WithDevToolsAPI
-    @Ignore
     @Test fun evaluateJS() {
         assertThat("JS string result should be correct",
                    sessionRule.session.evaluateJS("'foo'") as String, equalTo("foo"))
 
         assertThat("JS number result should be correct",
                    sessionRule.session.evaluateJS("1+1") as Double, equalTo(2.0))
 
         assertThat("JS boolean result should be correct",
@@ -1203,45 +1201,42 @@ class GeckoSessionTestRuleTest : BaseSes
                    hasEntry("tagName", "BODY"))
 
         assertThat("JS DOM array result should be correct",
                    sessionRule.session.evaluateJS("document.childNodes").asJSList<Any>(),
                    not(empty()))
     }
 
     @WithDevToolsAPI
-    @Ignore
     @Test fun evaluateJS_windowObject() {
         sessionRule.session.loadTestPath(HELLO_HTML_PATH)
         sessionRule.session.waitForPageStop()
 
         // Make sure we can access large objects like "window", which can strain our RDP connection.
         // Also make sure we can dynamically access sub-objects like Location.
         assertThat("JS DOM window result should be correct",
                    (sessionRule.session.evaluateJS("window")
                            dot "location"
                            dot "pathname") as String,
                    equalTo(HELLO_HTML_PATH))
     }
 
     @WithDevToolsAPI
-    @Ignore
     @Test fun evaluateJS_multipleSessions() {
         val newSession = sessionRule.createOpenSession()
 
         sessionRule.session.evaluateJS("this.foo = 42")
         assertThat("Variable should be set",
                    sessionRule.session.evaluateJS("this.foo") as Double, equalTo(42.0))
 
         assertThat("New session should have separate JS context",
                    newSession.evaluateJS("this.foo"), nullValue())
     }
 
     @WithDevToolsAPI
-    @Ignore
     @Test fun evaluateJS_jsToString() {
         val obj = sessionRule.session.evaluateJS("({foo:'bar'})")
         assertThat("JS object toString should follow lazy evaluation",
                    obj.toString(), equalTo("[Object]"))
 
         assertThat("JS object should be correct",
                    (obj dot "foo") as String, equalTo("bar"))
         assertThat("JS object toString should be expanded after evaluation",
@@ -1258,21 +1253,19 @@ class GeckoSessionTestRuleTest : BaseSes
     }
 
     @Test(expected = AssertionError::class)
     fun evaluateJS_throwOnNotWithDevTools() {
         sessionRule.session.evaluateJS("0")
     }
 
     @WithDevToolsAPI
-    @Ignore
     @Test(expected = RuntimeException::class)
     fun evaluateJS_throwOnJSException() {
         sessionRule.session.evaluateJS("throw Error()")
     }
 
     @WithDevToolsAPI
-    @Ignore
     @Test(expected = RuntimeException::class)
     fun evaluateJS_throwOnSyntaxError() {
         sessionRule.session.evaluateJS("<{[")
     }
 }
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java
@@ -720,17 +720,17 @@ public class GeckoSessionTestRule extend
     }
 
     protected void applyAnnotations(final Collection<Annotation> annotations,
                                     final GeckoSessionSettings settings) {
         for (final Annotation annotation : annotations) {
             if (TimeoutMillis.class.equals(annotation.annotationType())) {
                 // Scale timeout based on the default timeout to account for the device under test.
                 final long value = ((TimeoutMillis) annotation).value();
-                final long timeout = value * getDefaultTimeoutMillis() / DEFAULT_TIMEOUT_MILLIS;
+                final long timeout = value * getScaledTimeoutMillis() / DEFAULT_TIMEOUT_MILLIS;
                 mTimeoutMillis = Math.max(timeout, 1000);
             } else if (Setting.class.equals(annotation.annotationType())) {
                 ((Setting) annotation).key().set(settings, ((Setting) annotation).value());
             } else if (Setting.List.class.equals(annotation.annotationType())) {
                 for (final Setting setting : ((Setting.List) annotation).value()) {
                     setting.key().set(settings, setting.value());
                 }
             } else if (NullDelegate.class.equals(annotation.annotationType())) {
@@ -756,29 +756,33 @@ public class GeckoSessionTestRule extend
             return (RuntimeException) cause;
         } else if (e instanceof RuntimeException) {
             return (RuntimeException) e;
         }
 
         return new RuntimeException(cause != null ? cause : e);
     }
 
-    private long getDefaultTimeoutMillis() {
+    private long getScaledTimeoutMillis() {
         if ("x86".equals(env.getCPUArch())) {
             return env.isEmulator() ? DEFAULT_X86_EMULATOR_TIMEOUT_MILLIS
                                     : DEFAULT_X86_DEVICE_TIMEOUT_MILLIS;
         }
         return env.isEmulator() ? DEFAULT_ARM_EMULATOR_TIMEOUT_MILLIS
                                 : DEFAULT_ARM_DEVICE_TIMEOUT_MILLIS;
     }
 
+    private long getDefaultTimeoutMillis() {
+        return env.isDebugging() ? DEFAULT_IDE_DEBUG_TIMEOUT_MILLIS
+                                 : getScaledTimeoutMillis();
+    }
+
     protected void prepareStatement(final Description description) throws Throwable {
         final GeckoSessionSettings settings = new GeckoSessionSettings(mDefaultSettings);
-        mTimeoutMillis = env.isDebugging() ? DEFAULT_IDE_DEBUG_TIMEOUT_MILLIS
-                                           : getDefaultTimeoutMillis();
+        mTimeoutMillis = getDefaultTimeoutMillis();
         mNullDelegates = new HashSet<>();
         mClosedSession = false;
         mWithDevTools = false;
 
         applyAnnotations(Arrays.asList(description.getTestClass().getAnnotations()), settings);
         applyAnnotations(description.getAnnotations(), settings);
 
         final List<CallRecord> records = new ArrayList<>();
@@ -890,18 +894,17 @@ public class GeckoSessionTestRule extend
         if (mWithDevTools) {
             if (sRDPConnection == null) {
                 final String dataDir = InstrumentationRegistry.getTargetContext()
                                                               .getApplicationInfo().dataDir;
                 final LocalSocketAddress address = new LocalSocketAddress(
                         dataDir + "/firefox-debugger-socket",
                         LocalSocketAddress.Namespace.FILESYSTEM);
                 sRDPConnection = new RDPConnection(address);
-                sRDPConnection.setTimeout((int) Math.min(DEFAULT_TIMEOUT_MILLIS,
-                                                         Integer.MAX_VALUE));
+                sRDPConnection.setTimeout(mTimeoutMillis);
             }
             final Tab tab = sRDPConnection.getMostRecentTab();
             tab.attach();
             mRDPTabs.put(session, tab);
         }
     }
 
     private void waitForInitialLoad(final GeckoSession session) {