Skip to content
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

Adding test of serial form of program.dat including pickles #489

Merged
merged 3 commits into from
Dec 2, 2021
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
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildPlugin(useContainerAgent: true, configurations: [
[ platform: "linux", jdk: "8" ],
[ platform: "docker", jdk: "8" ],
[ platform: "windows", jdk: "8" ],
[ platform: "linux", jdk: "11" ]
])
13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<jenkins.version>2.222.4</jenkins.version>
<java.level>8</java.level>
<jenkins-test-harness.version>1661.vca80dbae839b</jenkins-test-harness.version> <!-- TODO until in parent POM -->
<no-test-jar>false</no-test-jar>
<groovy-cps.version>1.32</groovy-cps.version>
<node.version>12.19.0</node.version>
Expand Down Expand Up @@ -253,6 +254,18 @@
<artifactId>pipeline-stage-step</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.16.2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<resources>
Expand Down
100 changes: 100 additions & 0 deletions src/test/java/org/jenkinsci/plugins/workflow/cps/SerialFormTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* The MIT License
*
* Copyright 2021 CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.jenkinsci.plugins.workflow.cps;

import hudson.model.Node;
import hudson.model.Slave;
import hudson.slaves.SlaveComputer;
import java.net.URL;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.pickles.Pickle;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.RealJenkinsRule;
import org.jvnet.hudson.test.recipes.LocalData;
import org.testcontainers.DockerClientFactory;
import org.testcontainers.Testcontainers;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.utility.MountableFile;

/**
* Test compatibility of the format of {@code program.dat} as well as various {@link Pickle}s.
*/
public class SerialFormTest {

private static final String AGENT_NAME = "remote";
private static final String AGENT_SECRET = "defebc83e8736659464a172801f43de376f751891e69cb6ece89e856d6cc3b48";

private static GenericContainer<?> agentContainer;

@BeforeClass public static void dockerCheck() throws Exception {
try {
DockerClientFactory.instance().client();
} catch (Exception x) {
Assume.assumeNoException("does not look like Docker is available", x);
}
}

@AfterClass public static void terminateContainer() throws Exception {
if (agentContainer != null && agentContainer.isRunning()) {
agentContainer.stop();
}
}

@Rule public RealJenkinsRule rr = new RealJenkinsRule();

@LocalData
@Test public void persistence() throws Throwable {
rr.startJenkins();
URL u = rr.getUrl();
Testcontainers.exposeHostPorts(u.getPort());
agentContainer = new GenericContainer<>("jenkins/inbound-agent").
withEnv("JENKINS_URL", new URL(u.getProtocol(), "host.testcontainers.internal", u.getPort(), u.getFile()).toString()).
withEnv("JENKINS_AGENT_NAME", AGENT_NAME).
withEnv("JENKINS_SECRET", AGENT_SECRET).
withEnv("JENKINS_WEB_SOCKET", "true");
agentContainer.start();
agentContainer.copyFileToContainer(MountableFile.forClasspathResource(SerialFormTest.class.getName().replace('.', '/') + "/persistence-workspace"), "/home/jenkins/agent/workspace");
rr.runRemotely(SerialFormTest::_persistence);
}
private static void _persistence(JenkinsRule r) throws Throwable {
Node agent = r.jenkins.getNode(AGENT_NAME);
assertThat(agent, notNullValue());
assertThat(((SlaveComputer) agent.toComputer()).getJnlpMac(), is(AGENT_SECRET));
r.waitOnline((Slave) agent);
WorkflowJob p = r.jenkins.getItemByFullName("p", WorkflowJob.class);
WorkflowRun b = p.getBuildByNumber(1);
r.assertBuildStatusSuccess(r.waitForCompletion(b));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
+ touch running
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
+ [ -f running ]
+ sleep 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
touch running; while [ -f running ]; do sleep 1; done
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version='1.1' encoding='UTF-8'?>
Copy link
Member

Choose a reason for hiding this comment

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

nit: Personally I prefer to use ZIP files with @LocalData so this kind of stuff does not come up in GitHub searches, but maybe you prefer doing things this way for other reasons.

Copy link
Member Author

Choose a reason for hiding this comment

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

come up in GitHub searches

Could be an issue I suppose. I normally prefer exploded $JENKINS_HOME because it is easier to review, and occasionally it even makes sense to change one line of one file, which in a ZIP would just be an opaque blob.

<flow-build plugin="[email protected]">
<actions>
<jenkins.metrics.impl.TimeInQueueAction plugin="[email protected]">
<queuingDurationMillis>34</queuingDurationMillis>
</jenkins.metrics.impl.TimeInQueueAction>
</actions>
<queueId>1</queueId>
<timestamp>1638308102618</timestamp>
<startTime>1638308102633</startTime>
<duration>0</duration>
<charset>UTF-8</charset>
<keepLog>false</keepLog>
<execution class="org.jenkinsci.plugins.workflow.cps.CpsFlowExecution">
<result>SUCCESS</result>
<script>node(&apos;remote&apos;) {sh &apos;touch running; while [ -f running ]; do sleep 1; done&apos;}</script>
<loadedScripts class="map"/>
<durabilityHint>MAX_SURVIVABILITY</durabilityHint>
<timings class="map">
<entry>
<string>flowNode</string>
<long>71664725</long>
</entry>
<entry>
<string>classLoad</string>
<long>503032612</long>
</entry>
<entry>
<string>run</string>
<long>2013078534</long>
</entry>
<entry>
<string>parse</string>
<long>634788612</long>
</entry>
<entry>
<string>saveProgram</string>
<long>157243273</long>
</entry>
</timings>
<sandbox>true</sandbox>
<iota>5</iota>
<head>1:5</head>
<start>2</start>
<done>false</done>
<resumeBlocked>false</resumeBlocked>
</execution>
<completed>false</completed>
<checkouts class="hudson.util.PersistedList"/>
</flow-build>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Started
Running in Durability level: MAX_SURVIVABILITY
ha:////4C4s8GpgRgC7jL1Vc6+MQZUhj5+pxM2y2IilVjG9e5RaAAAAoh+LCAAAAAAAAP9tjTEOwjAQBM8BClpKHuFItIiK1krDC0x8GCfWnbEdkooX8TX+gCESFVvtrLSa5wtWKcKBo5UdUu8otU4GP9jS5Mixv3geZcdn2TIl9igbHBs2eJyx4YwwR1SwULBGaj0nRzbDRnX6rmuvydanHMu2V1A5c4MHCFXMWcf8hSnC9jqYxPTz/BXAFEIGsfuclm8zQVqFvQAAAA==[Pipeline] Start of Pipeline
ha:////4MwOmZDnQUlX3FPa62Hf2kYUe6i49FlqM4oh1HuXCGDxAAAApR+LCAAAAAAAAP9tjTEOwjAUQ3+KOrAycohUghExsUZZOEFIQkgb/d8mKe3EibgadyBQiQlLlmxL1nu+oE4RjhQdby12HpP2vA+jK4lPFLtroIm3dOGaMFGwXNpJkrGnpUrKFhaxClYC1hZ1oOTRZdiIVt1VExS65pxj2Q4CKm8GeAAThZxVzN8yR9jeRpMIf5y/AJj7DGxXvP/86jduZBmjwAAAAA==[Pipeline] node
Running on ha:////4CLaJebQ3Knjt6rAddxf+RuWnS4i436VjAMYkt3tHTz2AAAAnB+LCAAAAAAAAP9b85aBtbiIQTGjNKU4P08vOT+vOD8nVc83PyU1x6OyILUoJzMv2y+/JJUBAhiZGBgqihhk0NSjKDWzXb3RdlLBUSYGJk8GtpzUvPSSDB8G5tKinBIGIZ+sxLJE/ZzEvHT94JKizLx0a6BxUmjGOUNodHsLgAy2EgZB/eT83ILSktQi/aLUXKAafQAiQtsUxgAAAA==remote in /home/jenkins/agent/workspace/p
ha:////4DkY9lqEYg4baTEkb2FhC5+BuwytGxWEN+/Kps71hDEwAAAApR+LCAAAAAAAAP9tjTEOwjAUQ3+KOrAycoh0gA0xsUZZOEFIQkgb/d8mKe3EibgadyBQiQlLlmxL1nu+oE4RjhQdby12HpP2vA+jK4lPFLtroIm3dOGaMFGwXNpJkrGnpUrKFhaxClYC1hZ1oOTRZdiIVt1VExS65pxj2Q4CKm8GeAAThZxVzN8yR9jeRpMIf5y/AJj7DGxXvP/86jfoP95RwAAAAA==[Pipeline] {
ha:////4N75xltGAcmBKGhiYVX84T5NICPl/mFx9RvMgEd8+nJ1AAAAoh+LCAAAAAAAAP9tjTEOAiEURD9rLGwtPQTbaGWsbAmNJ0AWEZb8zwLrbuWJvJp3kLiJlZNMMm+a93rDOic4UbLcG+wdZu14DKOti0+U+lugiXu6ck2YKRguzSSpM+cFJRUDS1gDKwEbgzpQdmgLbIVXD9UGhba9lFS/o4DGdQM8gYlqLiqVL8wJdvexy4Q/z18BzLEA29ce4gdpL1fxvAAAAA==[Pipeline] sh
+ touch running
+ [ -f running ]
+ sleep 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
670 3
998
1595 5
1638
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version='1.1' encoding='UTF-8'?>
<Tag plugin="[email protected]">
<node class="org.jenkinsci.plugins.workflow.graph.FlowStartNode" plugin="[email protected]">
<parentIds/>
<id>2</id>
</node>
<actions>
<wf.a.TimingAction plugin="[email protected]">
<startTime>1638308103597</startTime>
</wf.a.TimingAction>
</actions>
</Tag>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version='1.1' encoding='UTF-8'?>
<Tag plugin="[email protected]">
<node class="cps.n.StepStartNode" plugin="workflow-cps@999999-SNAPSHOT">
<parentIds>
<string>2</string>
</parentIds>
<id>3</id>
<descriptorId>org.jenkinsci.plugins.workflow.support.steps.ExecutorStep</descriptorId>
</node>
<actions>
<s.a.LogStorageAction/>
<cps.a.ArgumentsActionImpl plugin="workflow-cps@999999-SNAPSHOT">
<arguments>
<entry>
<string>label</string>
<string>remote</string>
</entry>
</arguments>
<sensitiveVariables/>
<isUnmodifiedBySanitization>true</isUnmodifiedBySanitization>
</cps.a.ArgumentsActionImpl>
<wf.a.TimingAction plugin="[email protected]">
<startTime>1638308103856</startTime>
</wf.a.TimingAction>
<org.jenkinsci.plugins.workflow.support.steps.ExecutorStepExecution_-QueueItemActionImpl plugin="[email protected]">
<id>2</id>
</org.jenkinsci.plugins.workflow.support.steps.ExecutorStepExecution_-QueueItemActionImpl>
<s.a.WorkspaceActionImpl>
<node>remote</node>
<path>/home/jenkins/agent/workspace/p</path>
<labels class="sorted-set"/>
</s.a.WorkspaceActionImpl>
</actions>
</Tag>
Loading