Skip to content

Commit bba0906

Browse files
committed
Issue #50: Disable workspace auto build to speed up tests
1 parent fcd00c8 commit bba0906

File tree

4 files changed

+41
-15
lines changed

4 files changed

+41
-15
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ public void test06_modifyFile() throws Exception {
8181

8282
@Test
8383
public void test99_tearDown() {
84-
try {
85-
MicroclimateUtil.cleanup(connection);
86-
} catch (Exception e) {
87-
TestUtil.print("Test case cleanup failed", e);
88-
}
84+
doTearDown();
8985
TestUtil.print("Ending test: " + getName());
9086
}
9187

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,7 @@ public void test06_switchToRunMode() throws Exception {
8787

8888
@Test
8989
public void test99_tearDown() {
90-
try {
91-
MicroclimateUtil.cleanup(connection);
92-
} catch (Exception e) {
93-
TestUtil.print("Test case cleanup failed", e);
94-
}
90+
doTearDown();
9591
TestUtil.print("Ending test: " + getName());
9692
}
9793

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
import org.eclipse.core.resources.IMarker;
2020
import org.eclipse.core.resources.IProject;
2121
import org.eclipse.core.resources.IResource;
22+
import org.eclipse.core.resources.IWorkspace;
23+
import org.eclipse.core.resources.IWorkspaceDescription;
24+
import org.eclipse.core.resources.ResourcesPlugin;
25+
import org.eclipse.core.runtime.CoreException;
2226
import org.eclipse.debug.core.ILaunch;
2327
import org.eclipse.debug.core.model.IDebugTarget;
2428
import org.eclipse.ui.IMarkerResolution;
@@ -61,7 +65,12 @@ public abstract class BaseTest extends TestCase {
6165
protected static String relativeURL;
6266
protected static String srcPath;
6367

68+
protected static Boolean origAutoBuildSetting = null;
69+
6470
public void doSetup() throws Exception {
71+
// Disable workspace auto build
72+
origAutoBuildSetting = setWorkspaceAutoBuild(false);
73+
6574
// Create a microclimate connection
6675
connection = MicroclimateObjectFactory.createMicroclimateConnection(new URI(MICROCLIMATE_URI));
6776
MicroclimateConnectionManager.add(connection);
@@ -82,6 +91,19 @@ public void doSetup() throws Exception {
8291
assertNotNull("The " + projectName + " project should be imported in eclipse", project);
8392
}
8493

94+
public void doTearDown() {
95+
try {
96+
MicroclimateUtil.cleanup(connection);
97+
} catch (Exception e) {
98+
TestUtil.print("Test case cleanup failed", e);
99+
}
100+
101+
// Restore workspace auto build setting
102+
if (origAutoBuildSetting != null) {
103+
setWorkspaceAutoBuild(origAutoBuildSetting.booleanValue());
104+
}
105+
}
106+
85107
public void checkApp(String text) throws Exception {
86108
MicroclimateApplication app = connection.getAppByName(projectName);
87109
assertTrue("App should be in started state. Current state is: " + app.getAppState(), MicroclimateUtil.waitForAppState(app, AppState.STARTED, 120, 2));
@@ -200,5 +222,21 @@ protected void runQuickFix(IResource resource) throws Exception {
200222
resolutions[0].run(markers[0]);
201223
TestUtil.waitForJobs(10, 1);
202224
}
225+
226+
public static Boolean setWorkspaceAutoBuild(boolean enabled) {
227+
IWorkspace workspace = ResourcesPlugin.getWorkspace();
228+
IWorkspaceDescription wsDescription = workspace.getDescription();
229+
boolean origEnabled = wsDescription.isAutoBuilding();
230+
if (enabled != origEnabled) {
231+
try {
232+
wsDescription.setAutoBuilding(enabled);
233+
workspace.setDescription(wsDescription);
234+
return origEnabled ? Boolean.TRUE : Boolean.FALSE;
235+
} catch (CoreException e) {
236+
TestUtil.print("Failed to set workspace auto build enabled to: " + enabled, e);
237+
}
238+
}
239+
return null;
240+
}
203241

204242
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,7 @@ public void test06_runQuickFix() throws Exception {
8484

8585
@Test
8686
public void test99_tearDown() {
87-
try {
88-
MicroclimateUtil.cleanup(connection);
89-
} catch (Exception e) {
90-
TestUtil.print("Test case cleanup failed", e);
91-
}
87+
doTearDown();
9288
TestUtil.print("Ending test: " + getName());
9389
}
9490

0 commit comments

Comments
 (0)