Skip to content

Commit

Permalink
Merge pull request #373 from jglick/StepExecution.acceptAll
Browse files Browse the repository at this point in the history
`StepExecutionIterator.accept`
  • Loading branch information
jglick authored Jan 24, 2025
2 parents 4fb69c3 + 9dc0011 commit 03f7312
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@
<scope>import</scope>
<type>pom</type>
</dependency>
<!-- TODO until in BOM: -->
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>686.v603d058a_e148</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jenkinsci.plugins.workflow.flow;

import com.google.common.base.Function;
import com.google.common.collect.AbstractIterator;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
Expand Down Expand Up @@ -36,6 +35,7 @@
import java.util.concurrent.CancellationException;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
Expand Down Expand Up @@ -313,7 +313,7 @@ private void save(List<FlowExecutionOwner> copy) {
@Extension
public static class StepExecutionIteratorImpl extends StepExecutionIterator {
@Override
public ListenableFuture<?> apply(final Function<StepExecution, Void> f) {
public ListenableFuture<?> accept(Consumer<StepExecution> c) {
List<ListenableFuture<?>> all = new ArrayList<>();

for (FlowExecution e : FlowExecutionList.get()) {
Expand All @@ -325,7 +325,7 @@ public ListenableFuture<?> apply(final Function<StepExecution, Void> f) {
ListenableFuture<Void> results = Futures.transform(execs, (List<StepExecution> result) -> {
for (StepExecution se : result) {
try {
f.apply(se);
c.accept(se);
} catch (RuntimeException x) {
LOGGER.log(Level.WARNING, null, x);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ public class FlowExecutionListTest {
stuck.setDefinition(new CpsFlowDefinition("blockSynchronously 'stuck'", false));
var stuckBuild = stuck.scheduleBuild2(0).waitForStart();
await().atMost(5, TimeUnit.SECONDS).until(() -> SynchronousBlockingStep.isStarted("stuck"));
// Make FlowExecutionList$StepExecutionIteratorImpl.applyAll submit a task to the CpsVmExecutorService
// Make FlowExecutionList$StepExecutionIteratorImpl.acceptAll submit a task to the CpsVmExecutorService
// for stuck #1 that will never complete, so the resulting future will never complete.
StepExecution.applyAll(e -> null);
StepExecution.acceptAll(e -> {});
// Let notStuckBuild complete and clean up all references.
SemaphoreStep.success("wait/1", null);
r.waitForCompletion(notStuckBuild);
Expand Down Expand Up @@ -248,9 +248,9 @@ public class FlowExecutionListTest {
WeakReference<Object> notStuckBuildRef = new WeakReference<>(notStuckBuild);
var stuck = r.jenkins.getItemByFullName("stuck", WorkflowJob.class);
var stuckBuild = stuck.getBuildByNumber(1);
// Make FlowExecutionList$StepExecutionIteratorImpl.applyAll submit a task to the CpsVmExecutorService
// Make FlowExecutionList$StepExecutionIteratorImpl.acceptAll submit a task to the CpsVmExecutorService
// for stuck #1 that will never complete, so the resulting future will never complete.
StepExecution.applyAll(e -> null);
StepExecution.acceptAll(e -> {});
// Let notStuckBuild complete and clean up all references.
SemaphoreStep.success("wait/1", null);
r.waitForCompletion(notStuckBuild);
Expand Down

0 comments on commit 03f7312

Please sign in to comment.