提交 e147c51f 编写于 作者: C Christoph Kutzinski

there has been still a possible race condition in SurefireArchiver -...

there has been still a possible race condition in SurefireArchiver - synchronizing the whole block on build
上级 b093f44c
...@@ -124,12 +124,10 @@ public class SurefireArchiver extends MavenReporter { ...@@ -124,12 +124,10 @@ public class SurefireArchiver extends MavenReporter {
if(reportsDir.exists()) { if(reportsDir.exists()) {
// surefire:test just skips itself when the current project is not a java project // surefire:test just skips itself when the current project is not a java project
synchronized (build) {
FileSet fileSet = getFileSet(reportsDir); FileSet fileSet = getFileSet(reportsDir);
DirectoryScanner ds; DirectoryScanner ds = fileSet.getDirectoryScanner();
synchronized (fileSet) {
ds = fileSet.getDirectoryScanner();
}
if(ds.getIncludedFilesCount()==0) if(ds.getIncludedFilesCount()==0)
// no test in this module // no test in this module
...@@ -141,9 +139,7 @@ public class SurefireArchiver extends MavenReporter { ...@@ -141,9 +139,7 @@ public class SurefireArchiver extends MavenReporter {
if(result==null) result = new TestResult(); if(result==null) result = new TestResult();
result.parse(System.currentTimeMillis() - build.getMilliSecsSinceBuildStart(), reportsDir, reportFiles); result.parse(System.currentTimeMillis() - build.getMilliSecsSinceBuildStart(), reportsDir, reportFiles);
int failCount; int failCount = build.execute(new BuildCallable<Integer, IOException>() {
synchronized (build) {
failCount = build.execute(new BuildCallable<Integer, IOException>() {
public Integer call(MavenBuild build) throws IOException, InterruptedException { public Integer call(MavenBuild build) throws IOException, InterruptedException {
SurefireReport sr = build.getAction(SurefireReport.class); SurefireReport sr = build.getAction(SurefireReport.class);
if(sr==null) if(sr==null)
...@@ -156,7 +152,6 @@ public class SurefireArchiver extends MavenReporter { ...@@ -156,7 +152,6 @@ public class SurefireArchiver extends MavenReporter {
return result.getFailCount(); return result.getFailCount();
} }
}); });
}
// if surefire plugin is going to kill maven because of a test failure, // if surefire plugin is going to kill maven because of a test failure,
// intercept that (or otherwise build will be marked as failure) // intercept that (or otherwise build will be marked as failure)
...@@ -168,6 +163,7 @@ public class SurefireArchiver extends MavenReporter { ...@@ -168,6 +163,7 @@ public class SurefireArchiver extends MavenReporter {
Maven3Builder.markAsSuccess = true; Maven3Builder.markAsSuccess = true;
} }
} }
}
return true; return true;
} }
......
...@@ -38,6 +38,11 @@ import org.junit.Before; ...@@ -38,6 +38,11 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.Matchers; import org.mockito.Matchers;
/**
* Unit test for the JUnit result parsing in {@link SurefireArchiver}.
*
* @author kutzi
*/
public class SurefireArchiverUnitTest { public class SurefireArchiverUnitTest {
private SurefireArchiver archiver; private SurefireArchiver archiver;
...@@ -87,7 +92,6 @@ public class SurefireArchiverUnitTest { ...@@ -87,7 +92,6 @@ public class SurefireArchiverUnitTest {
URL resource = SurefireArchiverUnitTest.class.getResource("/surefire-archiver-test1"); URL resource = SurefireArchiverUnitTest.class.getResource("/surefire-archiver-test1");
File reportsDir = new File(resource.toURI().getPath()); File reportsDir = new File(resource.toURI().getPath());
doReturn(reportsDir).when(this.mojoInfo).getConfigurationValue("reportsDirectory", File.class); doReturn(reportsDir).when(this.mojoInfo).getConfigurationValue("reportsDirectory", File.class);
System.out.println("Using reports directory: " + reportsDir.getAbsolutePath());
this.archiver.postExecute(buildProxy, null, this.mojoInfo, new NullBuildListener(), null); this.archiver.postExecute(buildProxy, null, this.mojoInfo, new NullBuildListener(), null);
...@@ -100,7 +104,6 @@ public class SurefireArchiverUnitTest { ...@@ -100,7 +104,6 @@ public class SurefireArchiverUnitTest {
URL resource = SurefireArchiverUnitTest.class.getResource("/surefire-archiver-test2"); URL resource = SurefireArchiverUnitTest.class.getResource("/surefire-archiver-test2");
File reportsDir = new File(resource.toURI().getPath()); File reportsDir = new File(resource.toURI().getPath());
doReturn(reportsDir).when(this.mojoInfo).getConfigurationValue("reportsDirectory", File.class); doReturn(reportsDir).when(this.mojoInfo).getConfigurationValue("reportsDirectory", File.class);
System.out.println("Using reports directory: " + reportsDir.getAbsolutePath());
touchReportFiles(reportsDir); touchReportFiles(reportsDir);
this.archiver.postExecute(buildProxy, null, this.mojoInfo, new NullBuildListener(), null); this.archiver.postExecute(buildProxy, null, this.mojoInfo, new NullBuildListener(), null);
...@@ -115,7 +118,6 @@ public class SurefireArchiverUnitTest { ...@@ -115,7 +118,6 @@ public class SurefireArchiverUnitTest {
resource = SurefireArchiverUnitTest.class.getResource("/surefire-archiver-test3"); resource = SurefireArchiverUnitTest.class.getResource("/surefire-archiver-test3");
reportsDir = new File(resource.toURI().getPath()); reportsDir = new File(resource.toURI().getPath());
doReturn(reportsDir).when(this.mojoInfo).getConfigurationValue("reportsDirectory", File.class); doReturn(reportsDir).when(this.mojoInfo).getConfigurationValue("reportsDirectory", File.class);
System.out.println("Using reports directory: " + reportsDir.getAbsolutePath());
touchReportFiles(reportsDir); touchReportFiles(reportsDir);
this.archiver.postExecute(buildProxy, null, this.mojoInfo, new NullBuildListener(), null); this.archiver.postExecute(buildProxy, null, this.mojoInfo, new NullBuildListener(), null);
...@@ -132,7 +134,6 @@ public class SurefireArchiverUnitTest { ...@@ -132,7 +134,6 @@ public class SurefireArchiverUnitTest {
URL resource = SurefireArchiverUnitTest.class.getResource("/surefire-archiver-test2"); URL resource = SurefireArchiverUnitTest.class.getResource("/surefire-archiver-test2");
File reportsDir = new File(resource.toURI().getPath()); File reportsDir = new File(resource.toURI().getPath());
doReturn(reportsDir).when(this.mojoInfo).getConfigurationValue("reportsDirectory", File.class); doReturn(reportsDir).when(this.mojoInfo).getConfigurationValue("reportsDirectory", File.class);
System.out.println("Using reports directory: " + reportsDir.getAbsolutePath());
touchReportFiles(reportsDir); touchReportFiles(reportsDir);
FileSet fileSet = this.archiver.getFileSet(reportsDir); FileSet fileSet = this.archiver.getFileSet(reportsDir);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册