Skip to content

Commit 0b9bc81

Browse files
committed
Issue #91: fixStabilityOfLibertyTest
1 parent dd6ad97 commit 0b9bc81

File tree

2 files changed

+17
-9
lines changed
  • dev
    • com.ibm.microclimate.core/src/com/ibm/microclimate/core/internal
    • com.ibm.microclimate.test/src/com/ibm/microclimate/test

2 files changed

+17
-9
lines changed

dev/com.ibm.microclimate.core/src/com/ibm/microclimate/core/internal/HttpUtil.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,15 @@ public HttpResult(HttpURLConnection connection) throws IOException {
5757
if (!isGoodResponse) {
5858
MCLogger.logError("Received bad response code " + responseCode + " from "
5959
+ connection.getURL() + " - Error:\n" + error);
60-
}
61-
62-
InputStream is = connection.getInputStream();
63-
if (is != null) {
64-
response = MCUtil.readAllFromStream(is);
65-
}
66-
else {
6760
response = null;
61+
} else {
62+
InputStream is = connection.getInputStream();
63+
if (is != null) {
64+
response = MCUtil.readAllFromStream(is);
65+
}
66+
else {
67+
response = null;
68+
}
6869
}
6970
}
7071

dev/com.ibm.microclimate.test/src/com/ibm/microclimate/test/BaseTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,20 @@ protected void pingApp(String expectedText) throws Exception {
122122
URL url = app.getBaseUrl();
123123
url = new URL(url.toExternalForm() + relativeURL);
124124
HttpUtil.HttpResult result = HttpUtil.get(url.toURI());
125+
for (int i = 0; i < 15 && !result.isGoodResponse; i++) {
126+
Thread.sleep(1000);
127+
result = HttpUtil.get(url.toURI());
128+
}
125129
assertTrue("The response code should be 200: " + result.responseCode, result.responseCode == 200);
126130
assertTrue("The response should contain the expected text: " + expectedText, result.response != null && result.response.contains(expectedText));
127131
}
128132

129133
protected void checkMode(StartMode mode) throws Exception {
130134
MicroclimateApplication app = connection.getAppByName(projectName);
131-
assertTrue("App should be in mode: " + mode, app.getStartMode() == mode);
135+
for (int i = 0; i < 5 && app.getStartMode() != mode; i++) {
136+
Thread.sleep(1000);
137+
}
138+
assertTrue("App is in " + app.getStartMode() + " when it should be in " + mode + " mode.", app.getStartMode() == mode);
132139
ILaunch launch = ((MCEclipseApplication)app).getLaunch();
133140
if (StartMode.DEBUG_MODES.contains(mode)) {
134141
assertNotNull("There should be a launch for the app", launch);
@@ -145,7 +152,7 @@ protected void switchMode(StartMode mode) throws Exception {
145152
connection.requestProjectRestart(app, mode.startMode);
146153
// For Java builds the states can go by quickly so don't do an assert on this
147154
MicroclimateUtil.waitForAppState(app, AppState.STOPPED, 30, 1);
148-
assertTrue("App should be in started state", MicroclimateUtil.waitForAppState(app, AppState.STARTED, 120, 1));
155+
assertTrue("App should be in started state instead of: " + app.getAppState(), MicroclimateUtil.waitForAppState(app, AppState.STARTED, 120, 1));
149156
checkMode(mode);
150157
}
151158

0 commit comments

Comments
 (0)