diff options
author | Artur Signell <artur@vaadin.com> | 2013-11-29 18:18:04 +0200 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2013-12-02 18:58:04 +0200 |
commit | f040eb3824c45f47afc6d13323e7daaa496bf514 (patch) | |
tree | 290681a040244851dcf97d2ea6a5e3ff7bcaf0e1 | |
parent | b2bf7193d223fc576f8435cc45c145c97f6ce0bc (diff) | |
download | vaadin-framework-f040eb3824c45f47afc6d13323e7daaa496bf514.tar.gz vaadin-framework-f040eb3824c45f47afc6d13323e7daaa496bf514.zip |
Disable client timeout so websockets are not disconnected when idle (#13015)
Updated sleep method to ensure that long sleeps can be performed without losing
the connection to the browser
Change-Id: I4f29d946e7a9a400e303e3a574876e1bc2d56773
10 files changed, 131 insertions, 16 deletions
diff --git a/client/src/com/vaadin/client/communication/AtmospherePushConnection.java b/client/src/com/vaadin/client/communication/AtmospherePushConnection.java index 320ba9ebe7..95584412cd 100644 --- a/client/src/com/vaadin/client/communication/AtmospherePushConnection.java +++ b/client/src/com/vaadin/client/communication/AtmospherePushConnection.java @@ -348,6 +348,14 @@ public class AtmospherePushConnection implements PushConnection { state = State.CONNECT_PENDING; } + protected void onClientTimeout(AtmosphereResponse response) { + state = State.DISCONNECTED; + errorHandler + .onError( + "Client unexpectedly disconnected. Ensure client timeout is disabled.", + -1); + } + protected void onReconnect(JavaScriptObject request, final AtmosphereResponse response) { if (state == State.CONNECTED) { @@ -442,6 +450,7 @@ public class AtmospherePushConnection implements PushConnection { fallbackTransport: 'streaming', contentType: 'application/json; charset=UTF-8', reconnectInterval: 5000, + timeout: -1, maxReconnectOnClose: 10000000, trackMessageLength: true, enableProtocol: false, @@ -476,6 +485,9 @@ public class AtmospherePushConnection implements PushConnection { config.onReconnect = $entry(function(request, response) { self.@com.vaadin.client.communication.AtmospherePushConnection::onReconnect(*)(request, response); }); + config.onClientTimeout = $entry(function(request) { + self.@com.vaadin.client.communication.AtmospherePushConnection::onClientTimeout(*)(request); + }); return $wnd.jQueryVaadin.atmosphere.subscribe(config); }-*/; diff --git a/uitest/src/com/vaadin/tests/components/window/SubWindowsTextSelectionTest.java b/uitest/src/com/vaadin/tests/components/window/SubWindowsTextSelectionTest.java index 1df036af58..2e0873956c 100644 --- a/uitest/src/com/vaadin/tests/components/window/SubWindowsTextSelectionTest.java +++ b/uitest/src/com/vaadin/tests/components/window/SubWindowsTextSelectionTest.java @@ -15,7 +15,6 @@ */ package com.vaadin.tests.components.window; -import java.net.MalformedURLException; import java.util.ArrayList; import java.util.List; @@ -64,7 +63,7 @@ public class SubWindowsTextSelectionTest extends MultiBrowserTest { } @Test - public void verifyNoTextSelectionOnMove() throws MalformedURLException { + public void verifyNoTextSelectionOnMove() throws Exception { openTestURL(); diff --git a/uitest/src/com/vaadin/tests/push/BasicPushTest.java b/uitest/src/com/vaadin/tests/push/BasicPushTest.java index ef40ae09dc..e03262ca7e 100644 --- a/uitest/src/com/vaadin/tests/push/BasicPushTest.java +++ b/uitest/src/com/vaadin/tests/push/BasicPushTest.java @@ -25,7 +25,7 @@ import com.vaadin.tests.tb3.MultiBrowserTest; public abstract class BasicPushTest extends MultiBrowserTest { @Test - public void testPush() { + public void testPush() throws InterruptedException { openTestURL(); // Test client initiated push diff --git a/uitest/src/com/vaadin/tests/push/IdlePushChannelStreamingTest.java b/uitest/src/com/vaadin/tests/push/IdlePushChannelStreamingTest.java new file mode 100644 index 0000000000..f9a0a722e5 --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/IdlePushChannelStreamingTest.java @@ -0,0 +1,23 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.push; + +public class IdlePushChannelStreamingTest extends IdlePushChannelTest { + @Override + protected Class<?> getUIClass() { + return BasicPushStreaming.class; + } +} diff --git a/uitest/src/com/vaadin/tests/push/IdlePushChannelTest.java b/uitest/src/com/vaadin/tests/push/IdlePushChannelTest.java new file mode 100644 index 0000000000..4dcc8a680d --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/IdlePushChannelTest.java @@ -0,0 +1,37 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.push; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public abstract class IdlePushChannelTest extends MultiBrowserTest { + + private static final int SEVEN_MINUTES_IN_MS = 7 * 60 * 1000; + + @Test + public void longWaitBetweenActions() throws Exception { + openTestURL(); + BasicPushTest.getIncrementButton(this).click(); + Assert.assertEquals(1, BasicPushTest.getClientCounter(this)); + sleep(SEVEN_MINUTES_IN_MS); + BasicPushTest.getIncrementButton(this).click(); + Assert.assertEquals(2, BasicPushTest.getClientCounter(this)); + } + +} diff --git a/uitest/src/com/vaadin/tests/push/IdlePushChannelWebsocketTest.java b/uitest/src/com/vaadin/tests/push/IdlePushChannelWebsocketTest.java new file mode 100644 index 0000000000..3fd9c616fb --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/IdlePushChannelWebsocketTest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.push; + +import java.util.List; + +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.tests.tb3.WebsocketTest; + +public class IdlePushChannelWebsocketTest extends IdlePushChannelTest { + + @Override + protected Class<?> getUIClass() { + return BasicPushWebsocket.class; + } + + @Override + public List<DesiredCapabilities> getBrowsersToTest() { + return WebsocketTest.getWebsocketBrowsers(); + } +} diff --git a/uitest/src/com/vaadin/tests/push/PushLargeDataStreamingTest.java b/uitest/src/com/vaadin/tests/push/PushLargeDataStreamingTest.java index 8f10f0fbba..0d71c21118 100644 --- a/uitest/src/com/vaadin/tests/push/PushLargeDataStreamingTest.java +++ b/uitest/src/com/vaadin/tests/push/PushLargeDataStreamingTest.java @@ -24,7 +24,7 @@ import com.vaadin.tests.tb3.MultiBrowserTest; public class PushLargeDataStreamingTest extends MultiBrowserTest { @Test - public void testStreamingLargeData() { + public void testStreamingLargeData() throws InterruptedException { openTestURL(); // Without this there is a large chance that we will wait for all pushes @@ -38,7 +38,7 @@ public class PushLargeDataStreamingTest extends MultiBrowserTest { } - private void push() { + private void push() throws InterruptedException { // Wait for startButton to be present waitForElementToBePresent(vaadinLocatorById("startButton")); diff --git a/uitest/src/com/vaadin/tests/push/PushLargeDataWebsocketTest.java b/uitest/src/com/vaadin/tests/push/PushLargeDataWebsocketTest.java index 70a94f743e..cc8668a729 100644 --- a/uitest/src/com/vaadin/tests/push/PushLargeDataWebsocketTest.java +++ b/uitest/src/com/vaadin/tests/push/PushLargeDataWebsocketTest.java @@ -24,7 +24,7 @@ import com.vaadin.tests.tb3.WebsocketTest; public class PushLargeDataWebsocketTest extends WebsocketTest { @Test - public void testWebsocketLargeData() { + public void testWebsocketLargeData() throws Exception { openTestURL(); // Without this timing will be completly off as pushing "start" can @@ -38,7 +38,7 @@ public class PushLargeDataWebsocketTest extends WebsocketTest { } - private void push() { + private void push() throws Exception { // Wait for startButton to be present waitForElementToBePresent(vaadinLocatorById("startButton")); diff --git a/uitest/src/com/vaadin/tests/push/TogglePushTest.java b/uitest/src/com/vaadin/tests/push/TogglePushTest.java index 68d6f52b9f..1867f4a63a 100644 --- a/uitest/src/com/vaadin/tests/push/TogglePushTest.java +++ b/uitest/src/com/vaadin/tests/push/TogglePushTest.java @@ -24,7 +24,7 @@ import com.vaadin.tests.tb3.MultiBrowserTest; public class TogglePushTest extends MultiBrowserTest { @Test - public void togglePushInInit() { + public void togglePushInInit() throws Exception { setPush(true); String url = getTestUrl(); @@ -58,7 +58,7 @@ public class TogglePushTest extends MultiBrowserTest { } @Test - public void togglePush() { + public void togglePush() throws InterruptedException { setPush(true); openTestURL(); getDelayedCounterUpdateButton().click(); diff --git a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java index d7b7cd050f..f6fce18fae 100644 --- a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java +++ b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java @@ -74,6 +74,11 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { */ private static final int SCREENSHOT_WIDTH = 1500; + /** + * Timeout used by the TB grid + */ + private static final int BROWSER_TIMEOUT_IN_MS = 30 * 1000; + private DesiredCapabilities desiredCapabilities; private boolean debug = false; @@ -641,17 +646,21 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { } /** - * Helper method for sleeping X ms in a test. Catches and ignores - * InterruptedExceptions + * Sleeps for the given number of ms but ensures that the browser connection + * does not time out. * * @param timeoutMillis * Number of ms to wait + * @throws InterruptedException */ - protected void sleep(int timeoutMillis) { - try { - Thread.sleep(timeoutMillis); - } catch (InterruptedException e) { - throw new RuntimeException(e); + protected void sleep(int timeoutMillis) throws InterruptedException { + while (timeoutMillis > 0) { + int d = Math.min(BROWSER_TIMEOUT_IN_MS, timeoutMillis); + Thread.sleep(d); + timeoutMillis -= d; + + // Do something to keep the connection alive + getDriver().getTitle(); } } |