-
-
Notifications
You must be signed in to change notification settings - Fork 105
[JENKINS-52165] Stabilize and better test USE_WATCHING
#323
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 9 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
741c252
[JENKINS-52165] Enable `USE_WATCHING` by default
jglick 4159ede
c98bce4 broke diagnostic prints inside `handleExit` in `USE_WATCHING`…
jglick c69c1aa
`WATCHING_RECURRENCE_PERIOD` was too slow for `ExecutorStepTest.build…
jglick 97e3735
It was `Execution.check` I wanted, not `.run`
jglick a10a726
Added `RealJenkinsRule`-based test, and tuning `handleExit` behavior …
jglick fa91baa
Late output is sometimes lost in push mode
jglick 4f2b7e2
Pick up https://github.com/jenkinsci/durable-task-plugin/pull/185 & h…
jglick b7498d9
Ensuring that log streaming ceases when the channel is closed
jglick 64c4460
Using `OutputStreamTaskListener.Default`
jglick 3973de2
Bumps
jglick 59ff8a6
Merge branch 'master' of https://github.com/jenkinsci/workflow-durabl…
jglick 3296a8d
Bump
jglick b20d22a
Pick up https://github.com/jenkinsci/credentials-binding-plugin/pull/258
jglick a819ad2
Noting https://github.com/jenkinsci/remoting/pull/657
jglick 33bbec5
Merge branch 'master' of https://github.com/jenkinsci/workflow-durabl…
jglick b68e15f
Picking up https://github.com/jenkinsci/durable-task-plugin/pull/186,…
jglick 8e06d62
Turn `USE_WATCHING` back off by default, but run all relevant tests b…
jglick ed44750
Try `forkCount`
jglick 1f55bd4
Running the new `RealJenkinsRule` test also on Windows
jglick efdb3c0
https://github.com/jenkinsci/durable-task-plugin/pull/186 & https://g…
jglick 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
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
114 changes: 114 additions & 0 deletions
114
src/test/java/org/jenkinsci/plugins/workflow/steps/durable_task/RealShellStepTest.java
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 |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| /* | ||
| * The MIT License | ||
| * | ||
| * Copyright 2023 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.steps.durable_task; | ||
|
|
||
| import hudson.ExtensionList; | ||
| import hudson.Functions; | ||
| import hudson.model.ParametersAction; | ||
| import hudson.model.ParametersDefinitionProperty; | ||
| import hudson.model.StringParameterDefinition; | ||
| import hudson.model.StringParameterValue; | ||
| import hudson.slaves.AbstractCloudSlave; | ||
| import hudson.slaves.ComputerListener; | ||
| import java.io.File; | ||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
| import jenkins.slaves.restarter.JnlpSlaveRestarterInstaller; | ||
| import static org.awaitility.Awaitility.await; | ||
| import org.jenkinsci.plugins.durabletask.FileMonitoringTask; | ||
| import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; | ||
| import org.jenkinsci.plugins.workflow.job.WorkflowJob; | ||
| import org.jenkinsci.plugins.workflow.log.FileLogStorage; | ||
| import org.junit.Assume; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.jvnet.hudson.test.InboundAgentRule; | ||
| import org.jvnet.hudson.test.JenkinsRule; | ||
| import org.jvnet.hudson.test.PrefixedOutputStream; | ||
| import org.jvnet.hudson.test.RealJenkinsRule; | ||
| import org.jvnet.hudson.test.TailLog; | ||
|
|
||
| public final class RealShellStepTest { | ||
|
|
||
| private static final Logger LOGGER = Logger.getLogger(RealShellStepTest.class.getName()); | ||
|
|
||
| @Rule public RealJenkinsRule rr = new RealJenkinsRule(). | ||
| withColor(PrefixedOutputStream.Color.BLUE). | ||
| withLogger(DurableTaskStep.class, Level.FINE). | ||
| withLogger(FileMonitoringTask.class, Level.FINE); | ||
|
|
||
| @Rule public InboundAgentRule inboundAgents = new InboundAgentRule(); | ||
|
|
||
| @Test public void shellScriptExitingAcrossRestart() throws Throwable { | ||
| Assume.assumeFalse("TODO translate to batch script", Functions.isWindows()); | ||
| rr.startJenkins(); | ||
| rr.runRemotely(RealShellStepTest::disableJnlpSlaveRestarterInstaller); | ||
| inboundAgents.createAgent(rr, InboundAgentRule.Options.newBuilder(). | ||
| color(PrefixedOutputStream.Color.MAGENTA). | ||
| label("remote"). | ||
| withLogger(FileMonitoringTask.class, Level.FINER). | ||
| withLogger(DurableTaskStep.class, Level.FINEST). | ||
| withPackageLogger(FileLogStorage.class, Level.FINE). | ||
| build()); | ||
| try (var tailLog = new TailLog(rr, "p", 1).withColor(PrefixedOutputStream.Color.YELLOW)) { | ||
| rr.runRemotely(RealShellStepTest::shellScriptExitingAcrossRestart1); | ||
| rr.stopJenkins(); | ||
| var f = new File(rr.getHome(), "f"); | ||
| LOGGER.info(() -> "Waiting for " + f + " to be written…"); | ||
| await().until(f::isFile); | ||
| LOGGER.info("…done."); | ||
| rr.startJenkins(); | ||
| rr.runRemotely(RealShellStepTest::shellScriptExitingAcrossRestart2); | ||
| tailLog.waitForCompletion(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Simulate {@link AbstractCloudSlave} as in https://github.com/jenkinsci/jenkins/pull/7693. | ||
| * Most users should be using cloud agents, | ||
| * and this lets us preserve {@link InboundAgentRule.Options.Builder#withLogger(Class, Level)}. | ||
| */ | ||
| private static void disableJnlpSlaveRestarterInstaller(JenkinsRule r) throws Throwable { | ||
| ComputerListener.all().remove(ExtensionList.lookupSingleton(JnlpSlaveRestarterInstaller.class)); | ||
| } | ||
|
|
||
| private static void shellScriptExitingAcrossRestart1(JenkinsRule r) throws Throwable { | ||
| var p = r.createProject(WorkflowJob.class, "p"); | ||
| var f = new File(r.jenkins.getRootDir(), "f"); | ||
| p.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("F"))); | ||
| p.setDefinition(new CpsFlowDefinition("node('remote') {sh 'sleep 5 && touch \"$F\"'}", true)); | ||
| var b = p.scheduleBuild2(0, new ParametersAction(new StringParameterValue("F", f.getAbsolutePath()))).waitForStart(); | ||
| r.waitForMessage("+ sleep 5", b); | ||
| r.jenkins.doQuietDown(true, 0, null); | ||
| } | ||
|
|
||
| private static void shellScriptExitingAcrossRestart2(JenkinsRule r) throws Throwable { | ||
| var p = (WorkflowJob) r.jenkins.getItem("p"); | ||
| var b = p.getLastBuild(); | ||
| r.assertBuildStatusSuccess(r.waitForCompletion(b)); | ||
| r.assertLogContains("+ touch " + new File(r.jenkins.getRootDir(), "f"), b); | ||
| } | ||
|
|
||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.