Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLeo Ufimtsev2017-08-15 12:39:31 -0400
committerLeo Ufimtsev2017-08-15 12:39:31 -0400
commitab84ce04cbe7f494e3746d19d40968908097cd5d (patch)
treea53b69583f74dfcc464ad0e17bba948c8cd5814e /tests
parent3c94ea4602f0eed8a014963709ceb2125cbbc49d (diff)
downloadeclipse.platform.swt-ab84ce04cbe7f494e3746d19d40968908097cd5d.tar.gz
eclipse.platform.swt-ab84ce04cbe7f494e3746d19d40968908097cd5d.tar.xz
eclipse.platform.swt-ab84ce04cbe7f494e3746d19d40968908097cd5d.zip
Bug 517264 Refactor old Browser* tests -- Skip test_setUrl_remote on bad
connection. test_setUrl_remote() requires a live Internet connection. This test sometimes times out when a build server happens to have a bad Internet connection. This causes noise in the test logs. It's difficult to ensure live connectivity is always present, so instead this test will be skipped if there is no internet present. Note, setUrl(..) is still tested against local files even if an internet connection is not available. Change-Id: I098c1ecf3707c23260440fa0cf9081805198a627 Signed-off-by: Leo Ufimtsev <lufimtse@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java41
1 files changed, 39 insertions, 2 deletions
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java
index c73c055db9..741d04ee19 100644
--- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java
@@ -19,6 +19,10 @@ import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.time.Instant;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
@@ -791,12 +795,17 @@ public void test_setUrl_local() {
@Test
public void test_setUrl_remote() {
- // This test sometimes times out on windows build server. (as it uses internet)
+ // This test sometimes times out if build server has a bad connection. Thus for this test we have a longer timeout.
secondsToWaitTillFail = 35;
+ String url = "http://example.com"; // example.com loads very quickly and conveniently has a consistent title
+
+ // Skip this test if we don't have a working Internet connection.
+ assumeTrue("Skipping test due to bad internet connection", checkInternet(url));
+ testLog.append("checkInternet() passed");
+
String expectedTitle = "Example Domain";
Runnable browserSetFunc = () -> {
- String url = "http://example.com"; // example.com loads very quickly and conveniently has a consistent title
testLog.append("Setting Browser url to:" + url);
boolean opSuccess = browser.setUrl(url);
assertTrue("Expecting setUrl() to return true", opSuccess);
@@ -2237,4 +2246,32 @@ private String webkit1SkipMsg() {
return "Test_org_eclipse_swt_browser. Bug 509411. Skipping test on Webkit1 due to sporadic crash: "+ name.getMethodName();
}
+
+/**
+ * Check if Internet connection to a http url works.
+ *
+ * @param url a full url like http://www.example.com
+ * @return true if server responded with correct code (200), false otherwise.
+ */
+private static Boolean checkInternet(String url) {
+ HttpURLConnection connection = null;
+ try {
+ connection = (HttpURLConnection) new URL(url).openConnection();
+ connection.setRequestMethod("HEAD");
+ int code = connection.getResponseCode(); // 200 is success. See https://tools.ietf.org/html/rfc7231#section-6.3.1.
+ if (code == 200)
+ return true;
+ } catch (MalformedURLException e) {
+ System.err.println("Given url is malformed: " + url + "Try a fully formed url like: http://www.example.com");
+ e.printStackTrace();
+ } catch (IOException e) {
+ // No connection was made.
+ } finally {
+ if (connection != null) {
+ connection.disconnect();
+ }
+ }
+ return false;
+}
+
}

Back to the top