Skip to content

Commit

Permalink
Merge pull request #117 from zbynek/master
Browse files Browse the repository at this point in the history
[JENKINS-31660] avoid reading unnecessary test results from disk
  • Loading branch information
abayer authored May 7, 2019
2 parents 8d03260 + cc74b35 commit bcad82d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
16 changes: 7 additions & 9 deletions src/main/java/hudson/tasks/junit/CaseResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@ public int getPassCount() {
public int getFailedSince() {
// If we haven't calculated failedSince yet, and we should,
// do it now.
recomputeFailedSinceIfNeeded();
return failedSince;
}

private void recomputeFailedSinceIfNeeded() {
if (failedSince==0 && getFailCount()==1) {
CaseResult prev = getPreviousResult();
if(prev!=null && !prev.isPassed())
Expand All @@ -413,9 +418,8 @@ else if (getRun() != null) {
// failedSince will be 0, which isn't correct.
}
}
return failedSince;
}

public Run<?,?> getFailedSinceRun() {
return getRun().getParent().getBuildByNumber(getFailedSince());
}
Expand Down Expand Up @@ -637,13 +641,7 @@ public void setParentSuiteResult(SuiteResult parent) {
public void freeze(SuiteResult parent) {
this.parent = parent;
// some old test data doesn't have failedSince value set, so for those compute them.
if(!isPassed() && failedSince==0) {
CaseResult prev = getPreviousResult();
if(prev!=null && !prev.isPassed())
this.failedSince = prev.failedSince;
else
this.failedSince = getRun().getNumber();
}
recomputeFailedSinceIfNeeded();
}

public int compareTo(CaseResult that) {
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/hudson/tasks/junit/TestResultLinksTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@
import hudson.model.FreeStyleProject;
import hudson.model.Result;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.concurrent.TimeUnit;

import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.JenkinsRule.WebClient;
import org.jvnet.hudson.test.TouchBuilder;
Expand Down Expand Up @@ -117,4 +121,20 @@ public void testNonDescendantRelativePath() throws Exception {
boolean pathStartsWithRootUrl = !pathIsEmptyOrNull && relativePath2.startsWith(rule.jenkins.getRootUrl());
assertTrue("relative path is empty OR begins with the app root", pathIsEmptyOrNull || pathStartsWithRootUrl );
}

@Issue("JENKINS-31660")
@Test
public void testPreviousBuildNotLoaded() throws IOException, URISyntaxException {
TestResult testResult = new TestResult();
File dataFile = TestResultTest.getDataFile("SKIPPED_MESSAGE/skippedTestResult.xml");
testResult.parse(dataFile, null);
FreeStyleBuild build = new FreeStyleBuild(project) {
@Override
public FreeStyleBuild getPreviousBuild() {
fail("When no tests fail, we don't need tp load previous builds (expensive)");
return null;
}
};
testResult.freeze(new TestResultAction(build, testResult, null));
}
}
2 changes: 1 addition & 1 deletion src/test/java/hudson/tasks/junit/TestResultTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* @author dty
*/
public class TestResultTest {
private File getDataFile(String name) throws URISyntaxException {
protected static File getDataFile(String name) throws URISyntaxException {
return new File(TestResultTest.class.getResource(name).toURI());
}

Expand Down

0 comments on commit bcad82d

Please sign in to comment.