junit: cancel progress if exceptions on startup occur

testng: -||-; connect to server socket on cancel
This commit is contained in:
anna
2010-05-07 14:30:43 +04:00
parent d052e94117
commit e2d13b009a
2 changed files with 55 additions and 7 deletions
@@ -21,6 +21,7 @@ import com.intellij.execution.configurations.ConfigurationPerRunnerSettings;
import com.intellij.execution.configurations.RunnerSettings;
import com.intellij.execution.configurations.RuntimeConfigurationException;
import com.intellij.execution.configurations.RuntimeConfigurationWarning;
import com.intellij.execution.runners.ProgramRunner;
import com.intellij.execution.testframework.SourceScope;
import com.intellij.execution.testframework.TestSearchScope;
import com.intellij.openapi.application.ApplicationManager;
@@ -49,6 +50,8 @@ import java.net.Socket;
import java.util.Collection;
public class TestPackage extends TestObject {
private static BackgroundableProcessIndicator mySearchForTestsIndicator;
public TestPackage(final Project project,
final JUnitConfiguration configuration,
RunnerSettings runnerSettings,
@@ -62,6 +65,19 @@ public class TestPackage extends TestObject {
return data.getScope().getSourceScope(myConfiguration);
}
@Override
public ExecutionResult execute(Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
try {
return super.execute(executor, runner);
}
catch (ExecutionException e) {
if (mySearchForTestsIndicator != null && !mySearchForTestsIndicator.isCanceled()) {
mySearchForTestsIndicator.cancel(); //ensure that search for tests stops anyway
}
throw e;
}
}
protected void initialize() throws ExecutionException {
super.initialize();
final Project project = myConfiguration.getProject();
@@ -244,7 +260,7 @@ public class TestPackage extends TestObject {
}
}
};
ProgressManagerImpl.runProcessWithProgressAsynchronously(task, new BackgroundableProcessIndicator(task) {
mySearchForTestsIndicator = new BackgroundableProcessIndicator(task) {
@Override
public void cancel() {
try {//ensure that serverSocket.accept was interrupted
@@ -257,7 +273,8 @@ public class TestPackage extends TestObject {
}
super.cancel();
}
});
};
ProgressManagerImpl.runProcessWithProgressAsynchronously(task, mySearchForTestsIndicator);
}
private static boolean isSyncSearch() {
@@ -41,7 +41,8 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.module.LanguageLevelUtil;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator;
import com.intellij.openapi.progress.impl.ProgressManagerImpl;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.ex.JavaSdkUtil;
@@ -59,7 +60,10 @@ import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.util.PathUtil;
import com.intellij.util.net.NetUtils;
import com.theoryinpractice.testng.model.*;
import com.theoryinpractice.testng.model.IDEARemoteTestRunnerClient;
import com.theoryinpractice.testng.model.TestData;
import com.theoryinpractice.testng.model.TestNGRemoteListener;
import com.theoryinpractice.testng.model.TestType;
import com.theoryinpractice.testng.ui.TestNGConsoleView;
import com.theoryinpractice.testng.ui.TestNGResults;
import com.theoryinpractice.testng.ui.actions.RerunFailedTestsAction;
@@ -72,9 +76,11 @@ import org.testng.annotations.AfterClass;
import org.testng.remote.strprotocol.MessageHelper;
import javax.swing.*;
import java.io.*;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
public class TestNGRunnableState extends JavaCommandLineState {
@@ -86,6 +92,7 @@ public class TestNGRunnableState extends JavaCommandLineState {
private int port;
private String debugPort;
private File myTempFile;
private BackgroundableProcessIndicator mySearchForTestIndicator;
public TestNGRunnableState(ExecutionEnvironment environment, TestNGConfiguration config) {
super(environment);
@@ -114,9 +121,18 @@ public class TestNGRunnableState extends JavaCommandLineState {
@Override
public ExecutionResult execute(@NotNull final Executor executor, @NotNull final ProgramRunner runner) throws ExecutionException {
OSProcessHandler processHandler = null;
try {
processHandler = startProcess();
}
catch (ExecutionException e) {
if (mySearchForTestIndicator != null && !mySearchForTestIndicator.isCanceled()) {
mySearchForTestIndicator.cancel();
}
throw e;
}
final TestNGConsoleView console = new TestNGConsoleView(config, runnerSettings, myConfigurationPerRunnerSettings);
console.initUI();
OSProcessHandler processHandler = startProcess();
for (RunConfigurationExtension ext : Extensions.getExtensions(RunConfigurationExtension.EP_NAME)) {
ext.handleStartProcess(config, processHandler);
}
@@ -306,7 +322,22 @@ public class TestNGRunnableState extends JavaCommandLineState {
myTempFile = File.createTempFile("idea_testng", ".tmp");
myTempFile.deleteOnExit();
javaParameters.getProgramParametersList().add("-temp", myTempFile.getAbsolutePath());
ProgressManager.getInstance().run(new SearchingForTestsTask(serverSocket, is15, config, myTempFile));
final SearchingForTestsTask task = new SearchingForTestsTask(serverSocket, is15, config, myTempFile);
mySearchForTestIndicator = new BackgroundableProcessIndicator(task) {
@Override
public void cancel() {
try {//ensure that serverSocket.accept was interrupted
if (!serverSocket.isClosed()) {
new Socket(InetAddress.getLocalHost(), serverSocket.getLocalPort());
}
}
catch (Throwable e) {
LOG.info(e);
}
super.cancel();
}
};
ProgressManagerImpl.runProcessWithProgressAsynchronously(task, mySearchForTestIndicator);
}
catch (IOException e) {
LOG.error(e);