Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-31660] avoid reading unnecessary test results from disk #117

Merged
merged 1 commit into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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