Prevents GWTTestCase to become zombie when communication with backend fails.
Before this patch, when GWTTestCase fails to communicate with JUnitShell
for any reason (e.g. test case thrown a js exception which is not serializable),
then it was retrying indefinitely. This can cause to hang until the test case timeouts.
This patch changes the default for maximum retries and also provides an alternative
lightweight communication to JUnitShell to report something went wrong.
Change-Id: Ie02ea83e1363483c3bf2ca2dc5be6d9344cde2cf
Review-Link: https://gwt-review.googlesource.com/#/c/1880/
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@11510 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/junit/public/junit-standards.html b/user/src/com/google/gwt/junit/public/junit-standards.html
index 0d6fe07..dd86c95 100644
--- a/user/src/com/google/gwt/junit/public/junit-standards.html
+++ b/user/src/com/google/gwt/junit/public/junit-standards.html
@@ -24,7 +24,7 @@
<script language='javascript'>
<!--
function junitOnLoadErrorFn(moduleName) {
- junitError('Failed to load module "' + moduleName +
+ junitLaunchError('Failed to load module "' + moduleName +
'".\nPlease see the log for details.');
}
@@ -36,14 +36,21 @@
msg += '" was not specified';
}
msg += 'Allowed values: ' + allowedValues;
- junitError(msg);
+ junitLaunchError(msg);
}
-function junitError(msg) {
+function junitLaunchError(msg) {
+ junitError("launch", msg);
+}
+
+function junitError(type, msg) {
var xmlHttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
- xmlHttpRequest.open('POST', 'junithost/loadError', true);
+ xmlHttpRequest.open('POST', 'junithost/error/' + type, true);
xmlHttpRequest.setRequestHeader('Content-Type', 'text/x-gwt-rpc; charset=utf-8');
xmlHttpRequest.send(msg);
+ if (window.console && window.console.log) {
+ window.console.log(type + " error: " + msg);
+ }
}
function loadSelectionScript() {
diff --git a/user/src/com/google/gwt/junit/public/junit.html b/user/src/com/google/gwt/junit/public/junit.html
index e58ebce..c443c99 100644
--- a/user/src/com/google/gwt/junit/public/junit.html
+++ b/user/src/com/google/gwt/junit/public/junit.html
@@ -22,7 +22,7 @@
<script language='javascript'>
<!--
function junitOnLoadErrorFn(moduleName) {
- junitError('Failed to load module "' + moduleName +
+ junitLaunchError('Failed to load module "' + moduleName +
'".\nPlease see the log for details.');
}
@@ -34,14 +34,21 @@
msg += '" was not specified';
}
msg += 'Allowed values: ' + allowedValues;
- junitError(msg);
+ junitLaunchError(msg);
}
-function junitError(msg) {
+function junitLaunchError(msg) {
+ junitError("launch", msg);
+}
+
+function junitError(type, msg) {
var xmlHttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
- xmlHttpRequest.open('POST', 'junithost/loadError', true);
+ xmlHttpRequest.open('POST', 'junithost/error/' + type, true);
xmlHttpRequest.setRequestHeader('Content-Type', 'text/x-gwt-rpc; charset=utf-8');
xmlHttpRequest.send(msg);
+ if (window.console && window.console.log) {
+ window.console.log(type + " error: " + msg);
+ }
}
function loadSelectionScript() {
diff --git a/user/src/com/google/gwt/junit/server/JUnitHostImpl.java b/user/src/com/google/gwt/junit/server/JUnitHostImpl.java
index ef26877..5654ca7 100644
--- a/user/src/com/google/gwt/junit/server/JUnitHostImpl.java
+++ b/user/src/com/google/gwt/junit/server/JUnitHostImpl.java
@@ -1,12 +1,12 @@
/*
* Copyright 2008 Google Inc.
- *
+ *
* 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
@@ -19,8 +19,8 @@
import com.google.gwt.dev.util.StringKey;
import com.google.gwt.junit.JUnitFatalLaunchException;
import com.google.gwt.junit.JUnitMessageQueue;
-import com.google.gwt.junit.JUnitShell;
import com.google.gwt.junit.JUnitMessageQueue.ClientInfoExt;
+import com.google.gwt.junit.JUnitShell;
import com.google.gwt.junit.client.TimeoutException;
import com.google.gwt.junit.client.impl.JUnitHost;
import com.google.gwt.junit.client.impl.JUnitResult;
@@ -127,7 +127,11 @@
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String requestURI = request.getRequestURI();
- if (requestURI.endsWith("/junithost/loadError")) {
+ if (requestURI.endsWith("/junithost/error/fatal")) {
+ String msg = RPCServletUtils.readContentAsGwtRpc(request);
+ System.err.println("Fatal error: " + msg);
+ System.exit(1);
+ } else if (requestURI.endsWith("/junithost/error/launch")) {
String requestPayload = RPCServletUtils.readContentAsGwtRpc(request);
JUnitResult result = new JUnitResult();
initResult(request, result);
diff --git a/user/super/com/google/gwt/junit/translatable/com/google/gwt/junit/client/impl/GWTRunner.java b/user/super/com/google/gwt/junit/translatable/com/google/gwt/junit/client/impl/GWTRunner.java
index b4a1791..f9d58bf 100644
--- a/user/super/com/google/gwt/junit/translatable/com/google/gwt/junit/client/impl/GWTRunner.java
+++ b/user/super/com/google/gwt/junit/translatable/com/google/gwt/junit/client/impl/GWTRunner.java
@@ -1,12 +1,12 @@
/*
* Copyright 2008 Google Inc.
- *
+ *
* 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
@@ -36,7 +36,7 @@
/**
* The entry point class for GWTTestCases.
- *
+ *
* This is the main test running logic. Each time a test completes, the results
* are reported back through {@link #junitHost}, and the next method to run is
* returned. This process repeats until the next method to run is null.
@@ -72,7 +72,7 @@
/**
* The number of times we've failed to communicate with the server on the
- * current test batch.
+ * current test batch.
*/
private int curRetryCount = 0;
@@ -90,8 +90,7 @@
}
}.schedule(1000);
} else {
- // Give up and mark the test complete on the client side.
- markComplete();
+ reportFatalError("Cannot sync back to GWT junit backend: " + caught);
}
}
@@ -105,19 +104,8 @@
currentResults.clear();
if (currentBlock != null && currentBlock.getTests().length > 0) {
doRunTest();
- } else {
- markComplete();
}
}
-
- /**
- * Set a global expando so the test infrastructure knows that the test is
- * complete.
- */
- private native void markComplete() /*-{
- $doc.title = "Completed Tests";
- $wnd._gwt_test_complete = true;
- }-*/;
}
/**
@@ -216,7 +204,7 @@
* The maximum number of times to retry communication with the server per
* test batch.
*/
- private int maxRetryCount = -1;
+ private int maxRetryCount;
/**
* If true, run a single test case with no RPC.
@@ -240,7 +228,7 @@
public void onModuleLoad() {
clientInfo = new ClientInfo(parseQueryParamInteger(
SESSIONID_QUERY_PARAM, -1), getUserAgentProperty());
- maxRetryCount = parseQueryParamInteger(RETRYCOUNT_QUERY_PARAM, -1);
+ maxRetryCount = parseQueryParamInteger(RETRYCOUNT_QUERY_PARAM, 3);
currentBlock = checkForQueryParamTestToRun();
if (currentBlock != null) {
/*
@@ -324,7 +312,7 @@
*/
String currentPath = Window.Location.getPath();
String pathSuffix = currentPath.substring(currentPath.lastIndexOf('/'));
-
+
UrlBuilder builder = Window.Location.createUrlBuilder();
builder.setParameter(BLOCKINDEX_QUERY_PARAM,
Integer.toString(currentBlock.getIndex())).setPath(
@@ -348,7 +336,7 @@
/**
* Parse an integer from a query parameter, returning the default value if
* the parameter cannot be found.
- *
+ *
* @param paramName the parameter name
* @param defaultValue the default value
* @return the integer value of the parameter
@@ -408,4 +396,7 @@
}
}
+ private static native void reportFatalError(String errorMsg)/*-{
+ $wnd.junitError("fatal", errorMsg);
+ }-*/;
}