-
Notifications
You must be signed in to change notification settings - Fork 346
race condition and missing results in aggregation #732
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
017fc05
potential race condition in result aggregation
jtnord d5ff59a
update on finalized
jtnord 54d4976
If the jobs are not specified we need to calculate them on demand
jtnord fa3c186
filter downstream projects based on permissions
jtnord 2014944
Update src/main/java/hudson/tasks/test/AggregatedTestResultPublisher.…
jtnord 8c9b148
Update src/main/java/hudson/tasks/test/AggregatedTestResultPublisher.…
jtnord File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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; | ||
} | ||
|
||
|
@@ -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; | ||
|
@@ -144,43 +145,39 @@ | |
|
||
private transient List<AbstractProject> noFingerprints; | ||
|
||
@SuppressWarnings("deprecation") // calls getProject in constructor, so needs owner immediately | ||
/** | ||
* @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); | ||
} | ||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
} | ||
} | ||
|
@@ -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; | ||
|
@@ -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(); | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)