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

Fixing some test flakes #2556

Merged
merged 1 commit into from
Apr 10, 2024
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
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