Skip to content

Commit

Permalink
Remove shared session support from SessionTestSuite eclipse-platform#903
Browse files Browse the repository at this point in the history


The SessionTestSuite currently supports shared session. However, this
functionality is unused and only introduces unnecessary complexity to
the session test framework.

Contributes to
eclipse-platform#903
  • Loading branch information
HeikoKlare committed May 13, 2024
1 parent a055e52 commit 0aa429c
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public void run(TestResult result) {
fail(e);
}
}
if (!shouldSort || isSharedSession()) {
if (!shouldSort) {
// for shared sessions, we don't control the execution of test cases
super.run(result);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import junit.framework.TestCase;
import junit.framework.TestResult;
import junit.framework.TestSuite;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.tests.session.SetupManager.SetupException;

public class SessionTestSuite extends TestSuite {
Expand All @@ -33,8 +32,6 @@ public class SessionTestSuite extends TestSuite {
// the id for the plug-in whose classloader ought to be used to load the test case class
protected String pluginId;
private Setup setup;
// true if test cases should run in the same (shared) session
private boolean sharedSession;
protected SessionTestRunner testRunner;

public SessionTestSuite(String pluginId) {
Expand Down Expand Up @@ -123,46 +120,13 @@ private boolean isLocalTest(Test test) {
return localTests.contains(test);
}

public boolean isSharedSession() {
return sharedSession;
}

protected Setup newSetup() throws SetupException {
Setup base = SetupManager.getInstance().getDefaultSetup();
base.setSystemProperty("org.eclipse.update.reconcile", "false"); //$NON-NLS-1$ //$NON-NLS-2$
return base;
}

/**
* Runs this session test suite.
*/
@Override
public void run(TestResult result) {
if (!sharedSession) {
super.run(result);
return;
}
// running this session test suite in shared mode
Enumeration<Test> tests = tests();
Assert.isTrue(tests.hasMoreElements(), "A single test suite must be provided");
Test onlyTest = tests.nextElement();
Assert.isTrue(!tests.hasMoreElements(), "Only a single test suite can be run");
Assert.isTrue(onlyTest instanceof TestSuite, "Only test suites can be run in shared session mode");
TestSuite nested = (TestSuite) onlyTest;
try {
// in shared mode no TestDescriptors are used, need to set up environment ourselves
Setup localSetup = (Setup) getSetup().clone();
localSetup.setEclipseArgument(Setup.APPLICATION, applicationId);
localSetup.setEclipseArgument("testpluginname", pluginId);
localSetup.setEclipseArgument("classname", (nested.getName() != null ? nested.getName() : nested.getClass().getName()));
// run the session tests
new SessionTestRunner().run(this, result, localSetup, false);
} catch (SetupException e) {
result.addError(this, e.getCause());
return;
}
}

protected void runSessionTest(TestDescriptor test, TestResult result) {
try {
fillTestDescriptor(test);
Expand All @@ -175,11 +139,6 @@ protected void runSessionTest(TestDescriptor test, TestResult result) {

@Override
public final void runTest(Test test, TestResult result) {
if (sharedSession) {
// just for safety, prevent anybody from calling this API - we don't run individual tests when in shared mode
throw new UnsupportedOperationException();
}

if (test instanceof TestDescriptor) {
runSessionTest((TestDescriptor) test, result);
} else if (test instanceof TestCase) {
Expand Down Expand Up @@ -220,7 +179,4 @@ void setSetup(Setup setup) {
this.setup = setup;
}

public void setSharedSession(boolean sharedSession) {
this.sharedSession = sharedSession;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public SampleTests() {
// these tests should run in the same session (don't add to a non-shared session test suite)
SessionTestSuite shared = new SessionTestSuite(PI_HARNESS);
shared.addTestSuite(SameSessionTest.class);
shared.setSharedSession(true);
addTest(shared);
// play with a crash test
addTest(SampleCrashTest.suite());
Expand Down

0 comments on commit 0aa429c

Please sign in to comment.