Skip to content
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
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@
<scope>import</scope>
<type>pom</type>
</dependency>
<!-- TODO until in BOM: -->
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>1358.vfb_5780da_64cb_</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
Expand Down
25 changes: 11 additions & 14 deletions src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -541,15 +541,12 @@

private static final Map<String,WorkflowRun> LOADING_RUNS = new HashMap<>();

private String key() {
return getParent().getFullName() + '/' + getId();
}

/** Hack to allow {@link #execution} to use an {@link Owner} referring to this run, even when it has not yet been loaded. */
@Override public void reload() throws IOException {
LOGGER.fine(() -> "Adding " + key() + " to LOADING_RUNS");
LOGGER.fine(() -> "Adding " + getExternalizableId() + " to LOADING_RUNS");
synchronized (LOADING_RUNS) {
LOADING_RUNS.put(key(), this);
LOADING_RUNS.put(getExternalizableId(), this);
}

// super.reload() forces result to be FAILURE, so working around that
Expand Down Expand Up @@ -613,9 +610,9 @@
}
} finally { // Ensure the run is ALWAYS removed from loading even if something failed, so threads awaken.
checkouts(null); // only for diagnostics
LOGGER.fine(() -> "Removing " + key() + " from LOADING_RUNS");
LOGGER.fine(() -> "Removing " + getExternalizableId() + " from LOADING_RUNS");
synchronized (LOADING_RUNS) {
LOADING_RUNS.remove(key()); // or could just make the value type be WeakReference<WorkflowRun>
LOADING_RUNS.remove(getExternalizableId()); // or could just make the value type be WeakReference<WorkflowRun>
LOADING_RUNS.notifyAll();
}
}
Expand Down Expand Up @@ -944,14 +941,11 @@
id = run.getId();
this.run = run;
}
private String key() {
return job + '/' + id;
}
private @NonNull WorkflowRun run() throws IOException {
if (run==null) {
WorkflowRun candidate;
synchronized (LOADING_RUNS) {
candidate = LOADING_RUNS.get(key());
candidate = LOADING_RUNS.get(getExternalizableId());
}
if (candidate != null && candidate.getParent().getFullName().equals(job) && candidate.getId().equals(id)) {
run = candidate;
Expand Down Expand Up @@ -982,8 +976,8 @@
WorkflowRun r = run();
synchronized (LOADING_RUNS) {
int count = 5;
while (r.execution == null && LOADING_RUNS.containsKey(key()) && count-- > 0) {
try (WithThreadName naming = new WithThreadName(": waiting for " + key())) {
while (r.execution == null && LOADING_RUNS.containsKey(getExternalizableId()) && count-- > 0) {

Check warning on line 979 in src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 979 is only partially covered, 5 branches are missing
try (WithThreadName naming = new WithThreadName(": waiting for " + getExternalizableId())) {

Check warning on line 980 in src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 980 is not covered by tests
LOADING_RUNS.wait(/* 1m */60_000);
} catch (InterruptedException x) {
LOGGER.log(Level.WARNING, "failed to wait for " + r + " to be loaded", x);
Expand Down Expand Up @@ -1020,13 +1014,16 @@
@Override public String getUrl() throws IOException {
return run().getUrl();
}
@Override public @NonNull String getExternalizableId() {
return job + '#' + id;
}

@NonNull
@Override public TaskListener getListener() throws IOException {
return run().getListener();
}
@Override public String toString() {
return "Owner[" + key() + ":" + run + "]";
return getExternalizableId();
}

@Override
Expand Down
Loading