Skip to content

Commit

Permalink
Merge pull request #10 from jenkinsci/verify-timing-for-incomplete-pa…
Browse files Browse the repository at this point in the history
…rallels

Further verify timing for incomplete parallels fix from [JENKINS-38536]
  • Loading branch information
svanoort committed Jun 5, 2017
2 parents 6386693 + 788a52a commit 7d58d36
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 25 deletions.
44 changes: 21 additions & 23 deletions pom.xml
Expand Up @@ -6,7 +6,8 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.9</version>
<version>2.29</version>
<relativePath />
</parent>

<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -26,85 +27,82 @@
<properties>
<jenkins.version>1.642.3</jenkins.version>
<java.level>7</java.level>
<workflow.version>2.0</workflow.version>
<jackson.version>2.4.0</jackson.version>
</properties>

<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>${workflow.version}</version>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>2.2</version> <!-- allows consuming the new APIs -->
<version>2.17</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>2.17</version>
<scope>test</scope>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>pipeline-input-step</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<!-- For block-scoped stage support, input step handling -->
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>2.1</version>
<version>2.10</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>${workflow.version}</version>
<version>2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<!-- Needed to detect block-scoped stages -->
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>2.2</version>
<version>2.31</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<!-- Block-scoped stage support -->
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>pipeline-stage-step</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
<version>2.1</version>
<scope>test</scope>
<classifier>tests</classifier>
<version>2.14</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-aggregator</artifactId>
<version>${workflow.version}</version>
<artifactId>workflow-support</artifactId>
<version>2.14</version>
<scope>test</scope>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-durable-task-step</artifactId>
<version>${workflow.version}</version>
<version>2.5</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Expand Up @@ -24,8 +24,10 @@

package org.jenkinsci.plugins.workflow.pipelinegraphanalysis;

import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Collections2;
import hudson.model.Action;
import hudson.model.Result;
import org.apache.commons.lang.StringUtils;
Expand All @@ -51,6 +53,7 @@

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -388,7 +391,7 @@ public static GenericStatus condenseStatus(@Nonnull Collection<GenericStatus> st

/**
* Helper, prints flow graph in some detail - now a common utility so others don't have to reinvent it
* @param run
* @param run Run to show nodes for
* @param showTiming
* @param showActions
*/
Expand Down Expand Up @@ -428,10 +431,16 @@ private int parseIota(FlowNode node) {
System.out.println("Action format: ");
System.out.println("\t- actionClassName actionDisplayName");
System.out.println("------------------------------------------------------------------------------------------");
Function<FlowNode, String> flowNodeToId = new Function<FlowNode, String>(){
@Override
public String apply(@Nullable FlowNode input) {
return (input != null) ? input.getId() : null;
}
};
for (FlowNode node : sorted) {
StringBuilder formatted = new StringBuilder();
formatted.append('[').append(node.getId()).append(']');
formatted.append('{').append(StringUtils.join(node.getParentIds(), ',')).append('}');
formatted.append('{').append(StringUtils.join(Collections2.transform(node.getParents(), flowNodeToId), ',')).append('}');
if (showTiming) {
formatted.append('(');
if (node.getAction(TimingAction.class) != null) {
Expand Down
Expand Up @@ -33,6 +33,9 @@
import org.jenkinsci.plugins.workflow.flow.FlowExecution;
import org.jenkinsci.plugins.workflow.graph.BlockStartNode;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.graphanalysis.ForkScanner;
import org.jenkinsci.plugins.workflow.graphanalysis.NoOpChunkFinder;
import org.jenkinsci.plugins.workflow.graphanalysis.TestVisitor;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.support.steps.input.InputAction;
Expand Down Expand Up @@ -316,6 +319,42 @@ public void testInProgress() throws Exception {
SemaphoreStep.success("wait/1", null);
}


@Test
public void timingTest() throws Exception {
// Problem here: for runs in progress we should be using current time if they're the last run node, aka the in-progress node
String jobScript = ""+
"stage 'first'\n" +
"parallel 'long' : { sleep 10; }, \n" +
" 'short': { sleep 2; }";

// This must be amateur science fiction because the exposition for the setting goes on FOREVER
ForkScanner scan = new ForkScanner();
WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, "parallelTimes");
job.setDefinition(new CpsFlowDefinition(jobScript));
WorkflowRun run = job.scheduleBuild2(0).getStartCondition().get();
Thread.sleep(4000); // We need the short branch to be complete so we know timing should exceed its duration
FlowExecution exec = run.getExecution();
List<FlowNode> heads = exec.getCurrentHeads();
Assert.assertEquals(GenericStatus.IN_PROGRESS, StatusAndTiming.computeChunkStatus(
run, null, exec.getNode("2"), heads.get(0), null));
Assert.assertEquals(GenericStatus.SUCCESS, StatusAndTiming.computeChunkStatus(
run, null, exec.getNode("2"), heads.get(1), null));
TestVisitor visitor = new TestVisitor();
scan.setup(heads);
scan.visitSimpleChunks(heads, visitor, new NoOpChunkFinder());
TestVisitor.CallEntry entry = visitor.filteredCallsByType(TestVisitor.CallType.PARALLEL_END).get(0);
FlowNode endNode = exec.getNode(entry.getNodeId().toString());
Assert.assertEquals("sleep", endNode.getDisplayFunctionName());

// Finally, the heart of the matter: test computing durations
TimingInfo times = StatusAndTiming.computeChunkTiming(run, 0, exec.getNode("2"), exec.getNode(entry.getNodeId().toString()), null);
Assert.assertTrue("Underestimated duration", times.getTotalDurationMillis() >= 3000);

j.waitForCompletion(run);
j.assertBuildStatusSuccess(run);
}

@Test
public void testInProgressParallel() throws Exception {
WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, "Fails");
Expand Down

0 comments on commit 7d58d36

Please sign in to comment.