]> source.dussan.org Git - vaadin-framework.git/commitdiff
Made test more stable and added Firefox reconnect test (#12492)
authorArtur Signell <artur@vaadin.com>
Thu, 31 Oct 2013 19:35:25 +0000 (21:35 +0200)
committerVaadin Code Review <review@vaadin.com>
Fri, 1 Nov 2013 09:03:36 +0000 (09:03 +0000)
Waits longer for push message as at least Firefox has some kind of built in back off for websocket reconnects

Change-Id: Iaab2e09e8364f0b6247b3b39c19be439a4995800

uitest/src/com/vaadin/tests/push/PushReconnectTest.java
uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java
uitest/src/com/vaadin/tests/tb3/MultiBrowserTestWithProxy.java

index 8f131a505133e9b1db6f7a91f1a801b5ff9f8f1e..76a0b547da03457442d884c183e85b8f425198c7 100644 (file)
@@ -37,6 +37,26 @@ public abstract class PushReconnectTest extends MultiBrowserTestWithProxy {
         waitUntilServerCounterChanges();
     }
 
+    @Test
+    public void testUserActionWhileDisconnectedWithDelay() throws Exception {
+        setDebug(true);
+        openTestURL();
+        startTimer();
+        waitUntilServerCounterChanges();
+        disconnectProxy();
+        Assert.assertEquals(0, getClientCounter());
+        getIncrementClientCounterButton().click();
+        // No change while disconnected
+        Assert.assertEquals(0, getClientCounter());
+        // Firefox sends extra onopen calls after a while, which breaks
+        // everything
+        Thread.sleep(10000);
+        connectProxy();
+        waitUntilServerCounterChanges();
+        // The change should have appeared when reconnected
+        Assert.assertEquals(1, getClientCounter());
+    }
+
     @Test
     public void testUserActionWhileDisconnected() throws Exception {
         setDebug(true);
@@ -110,9 +130,9 @@ public abstract class PushReconnectTest extends MultiBrowserTestWithProxy {
         waitUntilServerCounterChanges();
         for (int i = 0; i < 50; i++) {
             disconnectProxy();
-            Thread.sleep(50);
+            Thread.sleep(100);
             connectProxy();
-            Thread.sleep(50);
+            Thread.sleep(100);
         }
         waitUntilServerCounterChanges();
         waitUntilServerCounterChanges();
@@ -134,7 +154,7 @@ public abstract class PushReconnectTest extends MultiBrowserTestWithProxy {
             public Boolean apply(WebDriver input) {
                 return BasicPushTest.getServerCounter(PushReconnectTest.this) > counter;
             }
-        });
+        }, 30);
     }
 
     private void startTimer() {
index 44cf06940215cddebf6aac2147f7e72b0e084b0b..e6acad780f552e9dc5c3c0ccf634c5254889ed34 100644 (file)
@@ -306,18 +306,31 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
     }
 
     /**
-     * Waits a short while for the given condition to become true. Use e.g. as
+     * Waits up to 10s for the given condition to become true. Use e.g. as
      * {@link #waitUntil(ExpectedConditions.textToBePresentInElement(by, text))}
      * 
      * @param condition
      *            the condition to wait for to become true
      */
     protected void waitUntil(ExpectedCondition<Boolean> condition) {
-        new WebDriverWait(driver, 10).until(condition);
+        waitUntil(condition, 10);
     }
 
     /**
-     * Waits a short while for the given condition to become false. Use e.g. as
+     * Waits the given number of seconds for the given condition to become true.
+     * Use e.g. as {@link
+     * #waitUntil(ExpectedConditions.textToBePresentInElement(by, text))}
+     * 
+     * @param condition
+     *            the condition to wait for to become true
+     */
+    protected void waitUntil(ExpectedCondition<Boolean> condition,
+            long timeoutInSeconds) {
+        new WebDriverWait(driver, timeoutInSeconds).until(condition);
+    }
+
+    /**
+     * Waits up to 10s for the given condition to become false. Use e.g. as
      * {@link #waitUntilNot(ExpectedConditions.textToBePresentInElement(by,
      * text))}
      * 
@@ -325,7 +338,20 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
      *            the condition to wait for to become false
      */
     protected void waitUntilNot(ExpectedCondition<Boolean> condition) {
-        new WebDriverWait(driver, 10).until(ExpectedConditions.not(condition));
+        waitUntilNot(condition, 10);
+    }
+
+    /**
+     * Waits the given number of seconds for the given condition to become
+     * false. Use e.g. as {@link
+     * #waitUntilNot(ExpectedConditions.textToBePresentInElement(by, text))}
+     * 
+     * @param condition
+     *            the condition to wait for to become false
+     */
+    protected void waitUntilNot(ExpectedCondition<Boolean> condition,
+            long timeoutInSeconds) {
+        waitUntil(ExpectedConditions.not(condition), timeoutInSeconds);
     }
 
     protected void waitForElementToBePresent(By by) {
index d3488a98c4cc9a70b94c069b857614bdc6add4dd..0bb76889a079552c5c6024e8f5d4ce6ce436992b 100755 (executable)
@@ -15,6 +15,7 @@
  */
 package com.vaadin.tests.tb3;
 
+import java.io.File;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.junit.After;
@@ -29,6 +30,11 @@ public abstract class MultiBrowserTestWithProxy extends MultiBrowserTest {
     private static AtomicInteger availablePort = new AtomicInteger(2000);
     private Session proxySession;
     private Integer proxyPort = null;
+    private JSch jsch;
+    private static String sshDir = System.getProperty("user.home") + "/.ssh/";
+    private String[] publicKeys = new String[] {
+            System.getProperty("sshkey.file"), sshDir + "id_rsa",
+            sshDir + "id_dsa", sshDir + "id_rsa2" };
 
     @Before
     public void setupInitialProxy() throws JSchException {
@@ -71,13 +77,21 @@ public abstract class MultiBrowserTestWithProxy extends MultiBrowserTest {
     }
 
     private void createProxy(int proxyPort) throws JSchException {
-        JSch j = new JSch();
-        String keyFile = System.getProperty("sshkey.file");
-        if (keyFile == null) {
-            keyFile = "~/.ssh/id_rsa";
+        if (jsch == null) {
+            jsch = new JSch();
+
+            String keyFile = null;
+            for (String publicKey : publicKeys) {
+                if (publicKey != null) {
+                    if (new File(publicKey).exists()) {
+                        keyFile = publicKey;
+                        break;
+                    }
+                }
+            }
+            jsch.addIdentity(keyFile);
         }
-        j.addIdentity(keyFile);
-        proxySession = j.getSession("localhost");
+        proxySession = jsch.getSession("localhost");
         proxySession.setConfig("StrictHostKeyChecking", "no");
         proxySession.setPortForwardingL("0.0.0.0", proxyPort,
                 super.getDeploymentHostname(), super.getDeploymentPort());