Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import hudson.model.Job;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.model.listeners.RunListener;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
Expand All @@ -53,6 +52,8 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.kohsuke.accmod.Restricted;
Expand Down Expand Up @@ -93,7 +94,7 @@
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
throws InterruptedException, IOException {
// add a TestResult just so that it can show up later.
build.addAction(new TestResultAction(jobs, includeFailedBuilds, build));
build.addAction(new TestResultAction(jobs, includeFailedBuilds));
return true;
}

Expand Down Expand Up @@ -126,13 +127,13 @@
private final boolean includeFailedBuilds;

/**
* The last time the fields of this object is computed from the rest.
* The reference of the lastChangedReference when we last recomputed the aggregation. if this is != lastChangedReference then we need to recomupte the results.
*/
private transient long lastUpdated = 0;
private transient Object lastRecomputedReference = null;
/**
* When was the last time any build completed?
* Unique Object set whenever a build completes.
*/
private static long lastChanged = 0;
private static volatile Object lastChangedReference = new Object();

private transient int failCount;
private transient int totalCount;
Expand All @@ -144,43 +145,39 @@

private transient List<AbstractProject> noFingerprints;

@SuppressWarnings("deprecation") // calls getProject in constructor, so needs owner immediately
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer true as calculation is defered, so the constructor was cleaned up (left as deprecated as it was public)

/**
* @deprecated use {@link #TestResultAction(String, boolean)}
*/
@Deprecated(forRemoval = true)
public TestResultAction(String jobs, boolean includeFailedBuilds, AbstractBuild<?, ?> owner) {
super(owner);
this.includeFailedBuilds = includeFailedBuilds;
this(jobs, includeFailedBuilds);
}

Check warning on line 154 in src/main/java/hudson/tasks/test/AggregatedTestResultPublisher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 153-154 are not covered by tests

if (jobs == null) {
// resolve null as the transitive downstream jobs
StringBuilder buf = new StringBuilder();
for (AbstractProject p : getProject().getTransitiveDownstreamProjects()) {
if (buf.length() > 0) {
buf.append(',');
}
buf.append(p.getFullName());
}
jobs = buf.toString();
}
Comment on lines -152 to -162
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to getJobs() so this is updated as the dependencyGraph is recomputed.

public TestResultAction(String jobs, boolean includeFailedBuilds) {
this.includeFailedBuilds = includeFailedBuilds;
this.jobs = jobs;
}

/**
* Gets the jobs to be monitored.
*/
public Collection<AbstractProject> getJobs() {
if (jobs == null) {

Check warning on line 165 in src/main/java/hudson/tasks/test/AggregatedTestResultPublisher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 165 is only partially covered, one branch is missing
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was the main fix for the failing internal ATH.

Set<AbstractProject> projects = getProject().getTransitiveDownstreamProjects();
return projects.stream().filter(p -> p.hasPermission(Item.READ)).collect(Collectors.toSet());
}
List<AbstractProject> r = new ArrayList<>();
if (jobs != null) {
for (String job : Util.tokenize(jobs, ",")) {
try {
AbstractProject j = Jenkins.get().getItemByFullName(job.trim(), AbstractProject.class);
if (j != null) {
r.add(j);
}
} catch (RuntimeException x) {
if (x.getClass().getSimpleName().startsWith("AccessDeniedException")) {
// just skip it
} else {
throw x;
}
for (String job : Util.tokenize(jobs, ",")) {
try {
AbstractProject j = Jenkins.get().getItemByFullName(job.trim(), AbstractProject.class);
if (j != null) {
r.add(j);
}
} catch (RuntimeException x) {
if (x.getClass().getSimpleName().startsWith("AccessDeniedException")) {
// just skip it
} else {
throw x;
}
}
}
Expand Down Expand Up @@ -271,10 +268,10 @@
justification = "False positive. Short-circuited")
private synchronized void upToDateCheck() {
// up to date check
if (lastUpdated > lastChanged) {
if (lastRecomputedReference == lastChangedReference) {
return;
}
lastUpdated = lastChanged + 1;
lastRecomputedReference = lastChangedReference;

int failCount = 0;
int totalCount = 0;
Expand Down Expand Up @@ -350,9 +347,10 @@

@Extension
public static class RunListenerImpl extends RunListener<Run> {
@SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", justification = "intended by design")
@Override
public void onCompleted(Run run, TaskListener listener) {
lastChanged = System.currentTimeMillis();
public void onFinalized(Run run) {
lastChangedReference = new Object();
}
}
}
Expand Down
Loading