Waits longer for push message as at least Firefox has some kind of built in back off for websocket reconnects
Change-Id: Iaab2e09e8364f0b6247b3b39c19be439a4995800
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);
waitUntilServerCounterChanges();
for (int i = 0; i < 50; i++) {
disconnectProxy();
- Thread.sleep(50);
+ Thread.sleep(100);
connectProxy();
- Thread.sleep(50);
+ Thread.sleep(100);
}
waitUntilServerCounterChanges();
waitUntilServerCounterChanges();
public Boolean apply(WebDriver input) {
return BasicPushTest.getServerCounter(PushReconnectTest.this) > counter;
}
- });
+ }, 30);
}
private void startTimer() {
}
/**
- * 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))}
*
* 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) {
*/
package com.vaadin.tests.tb3;
+import java.io.File;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.After;
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 {
}
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());