Sometimes TestCases like club.wpia.gigi.pages.admin
TestSEAdminPageUserMailSearch fail e.g. with CSRFExceptions. I debugged
this issue and have come to a conclusion:
Java's URL connection does not necessarily behave correctly, when
"keep-alive" logic and connection re-use is enabled: When a connection
is re-used and the request sometimes fails on the re-used connection
Java re-attempts to send the request. This might not be a good idea for
POST requests. Especially this is not a good idea, as we track forms
very strictly:
When a form gets requested, the instance is stored in the user's session
and can be submitted exactly once. When this POST request is repeated
the form has been submitted and a subsequent request will cause a
CSRFException. Disabling the retry-logic
is possible but also not a good alternative, as it also causes sporadic
POST-fails, which occur far more often that the retry-logic breaks a
Test Case.
The solution I chose ensures to close all HTTP-connections. Therefore
all HTTP requests use the same connection. This prevents timeouts
and does not cause POST retries. In particular I found problems with the
connection done to clear all caches. Using this change I observe that
all requests are made with the same connection and 100 subsequent
executions don't fail.
Change-Id: I1b4ebce92a431e5d35a81cecd8670b8c37eef9e1
return mainProps;
}
inited = true;
return mainProps;
}
inited = true;
+ url = testProps.getProperty("name.www") + ":" + testProps.getProperty("serverPort.https");
purgeDatabase();
String type = testProps.getProperty("type");
generateMainProps(mainProps);
if (type.equals("local")) {
purgeDatabase();
String type = testProps.getProperty("type");
generateMainProps(mainProps);
if (type.equals("local")) {
- url = testProps.getProperty("name.www") + ":" + testProps.getProperty("serverPort.https");
String[] parts = testProps.getProperty("mail").split(":", 2);
ter = new TestEmailReceiver(new InetSocketAddress(parts[0], Integer.parseInt(parts[1])));
ter.start();
String[] parts = testProps.getProperty("mail").split(":", 2);
ter = new TestEmailReceiver(new InetSocketAddress(parts[0], Integer.parseInt(parts[1])));
ter.start();
- url = testProps.getProperty("name.www") + ":" + testProps.getProperty("serverPort.https");
gigi = Runtime.getRuntime().exec(testProps.getProperty("java"));
DataOutputStream toGigi = new DataOutputStream(gigi.getOutputStream());
System.out.println("... starting server");
gigi = Runtime.getRuntime().exec(testProps.getProperty("java"));
DataOutputStream toGigi = new DataOutputStream(gigi.getOutputStream());
System.out.println("... starting server");
public static void purgeDatabase() throws SQLException, IOException {
purgeOnlyDB();
public static void purgeDatabase() throws SQLException, IOException {
purgeOnlyDB();
+ if (gigi != null) {
+ clearCaches();
+ }
}
public static void clearCaches() throws IOException {
ObjectCache.clearAllCaches();
// String type = testProps.getProperty("type");
URL u = new URL("https://" + getServerName() + "/manage");
}
public static void clearCaches() throws IOException {
ObjectCache.clearAllCaches();
// String type = testProps.getProperty("type");
URL u = new URL("https://" + getServerName() + "/manage");
- u.openConnection().getHeaderField("Location");
+ URLConnection connection = u.openConnection();
+ connection.getHeaderField("Location");
+ connection.getInputStream().close();
}
private static void generateMainProps(Properties mainProps) {
}
private static void generateMainProps(Properties mainProps) {