Skip to content

Commit

Permalink
Fixing some test flakes (#2556)
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick authored Apr 10, 2024
1 parent 7624bb1 commit 077e2e3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.jenkins.blueocean.blueocean_git_pipeline;

import com.mashape.unirest.http.exceptions.UnirestException;
import hudson.model.Computer;
import hudson.model.Executor;
import hudson.model.Item;
import hudson.model.ItemGroup;
import hudson.model.User;
Expand All @@ -15,6 +17,7 @@
import jenkins.model.ModifiableTopLevelItemGroup;
import jenkins.plugins.git.GitSampleRepoRule;
import org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval;
import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
Expand All @@ -25,6 +28,7 @@
import org.junit.runners.Parameterized.Parameters;
import org.jvnet.hudson.test.MockAuthorizationStrategy;
import org.jvnet.hudson.test.MockFolder;
import org.jvnet.hudson.test.RemainingActivityListener;
import org.jvnet.hudson.test.TestExtension;

import java.io.IOException;
Expand Down Expand Up @@ -64,6 +68,27 @@ public void setup() throws Exception{
setupScm();
}

/**
* Seems active only for {@link #shouldFailOnValidation4}.
* Could become another mode for {@link RemainingActivityListener}.
*/
@After
public void killIndexing() throws InterruptedException {
WAIT: while (true) {
for (Computer c : Jenkins.get().getComputers()) {
for (Executor x : c.getAllExecutors()) {
if (!x.isIdle()) {
System.err.println("Killing " + x.getCurrentExecutable());
x.interrupt();
Thread.sleep(1000);
continue WAIT;
}
}
}
break;
}
}

private Map createCredentials(User user, Map credRequest) throws UnirestException {
return new RequestBuilder(baseUrl)
.status(201)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.queue.QueueTaskFuture;
import hudson.tasks.Shell;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
Expand Down Expand Up @@ -231,15 +232,19 @@ public void getPipelineJobRuns() throws Exception {

job1.setConcurrentBuild(false);

WorkflowRun r = job1.scheduleBuild2(0).waitForStart();
job1.scheduleBuild2(0);
WorkflowRun b1 = job1.scheduleBuild2(0).waitForStart();
QueueTaskFuture<WorkflowRun> b2f = job1.scheduleBuild2(0);


List l = request().get("/organizations/jenkins/pipelines/pipeline1/runs").build(List.class);

Assert.assertEquals(2, l.size());
Assert.assertEquals("io.jenkins.blueocean.service.embedded.rest.QueuedBlueRun", ((Map) l.get(0)).get("_class"));
Assert.assertEquals("io.jenkins.blueocean.rest.impl.pipeline.PipelineRunImpl", ((Map) l.get(1)).get("_class"));

b2f.cancel(true);
b1.doStop();
j.waitForCompletion(b1);
}

@Test
Expand Down

0 comments on commit 077e2e3

Please sign in to comment.