Skip to content

Commit

Permalink
Flake in GitPipelineCreateRequestTest (#2468)
Browse files Browse the repository at this point in the history
* Flake in `GitPipelineCreateRequestTest`

* GithubPipelineCreateRequestTest.testOrgFolderIndexing` also flaky

* `GitScmTest.shouldCreateGitMbp` was also still running branch indexing at the end of a test

* `PipelineApiTest.testPipelineQueue` was not fully fixed in #2450

---------

Co-authored-by: Olivier Lamy <olamy@apache.org>
  • Loading branch information
jglick and olamy authored Aug 18, 2023
1 parent a30327b commit 104e940
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package io.jenkins.blueocean.blueocean_git_pipeline;

import com.mashape.unirest.http.exceptions.UnirestException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import hudson.model.User;
import io.jenkins.blueocean.commons.MapsHelper;
import io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest;
import java.util.List;
import java.util.Map;
import jenkins.branch.MultiBranchProject;
import jenkins.plugins.git.GitSCMSource;
import jenkins.plugins.git.GitSampleRepoRule;
Expand All @@ -13,34 +17,34 @@
import jenkins.plugins.git.traits.LocalBranchTrait;
import jenkins.scm.api.trait.SCMSourceTrait;
import jenkins.scm.api.trait.SCMTrait;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.junit.Assert;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.jvnet.hudson.test.BuildWatcher;

public class GitPipelineCreateRequestTest extends PipelineBaseTest {

@Rule
public GitSampleRepoRule sampleRepo = new GitSampleRepoRule();

@ClassRule
public static BuildWatcher watcher = new BuildWatcher();

@Before
public void createSomeStuff() throws Exception {
sampleRepo.init();
sampleRepo.write("Jenkinsfile", "pipeline { stage('Build 1') { steps { echo 'build' } } }");
sampleRepo.write("Jenkinsfile", "pipeline { agent any; stages { stage('Build 1') { steps { echo 'build' } } } }");
sampleRepo.write("file", "initial content");
sampleRepo.git("add", "Jenkinsfile");
sampleRepo.git("commit", "--all", "--message=flow");
}

@Test
public void createPipeline() throws UnirestException, IOException {
public void createPipeline() throws Exception {
j.jenkins.setQuietPeriod(0);
User user = login("vivek", "Vivek Pandey", "vivek.pandey@gmail.com");
Map r = new PipelineBaseTest.RequestBuilder(baseUrl)
.status(201)
Expand All @@ -63,6 +67,8 @@ public void createPipeline() throws UnirestException, IOException {
Assert.assertNotNull(SCMTrait.find(traits, CleanAfterCheckoutTrait.class));
Assert.assertNotNull(SCMTrait.find(traits, CleanBeforeCheckoutTrait.class));
Assert.assertNotNull(SCMTrait.find(traits, LocalBranchTrait.class));
j.waitUntilNoActivity();
j.waitForCompletion(j.jenkins.getItemByFullName("pipeline1/master", WorkflowJob.class).getBuildByNumber(1));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public void shouldFailForBadCredentialIdOnCreate() throws IOException, UnirestEx
}

@Test
public void shouldCreateGitMbp() throws IOException, UnirestException {
public void shouldCreateGitMbp() throws Exception {
login();
Map resp = new RequestBuilder(baseUrl)
.status(201)
Expand All @@ -242,6 +242,7 @@ public void shouldCreateGitMbp() throws IOException, UnirestException {
.build(Map.class);

assertEquals("demo", resp.get("name"));
j.waitUntilNoActivity();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.jenkins.blueocean.blueocean_github_pipeline;

import static org.junit.Assert.*;

import com.cloudbees.hudson.plugins.folder.AbstractFolderProperty;
import com.cloudbees.hudson.plugins.folder.computed.ComputedFolder;
import com.cloudbees.jenkins.GitHubWebHook;
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.CredentialsScope;
Expand All @@ -11,7 +14,6 @@
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;
import com.mashape.unirest.http.exceptions.UnirestException;
import hudson.model.Item;
import hudson.model.TopLevelItem;
import hudson.model.User;
import io.jenkins.blueocean.commons.MapsHelper;
import io.jenkins.blueocean.commons.ServiceException;
Expand All @@ -26,6 +28,10 @@
import io.jenkins.blueocean.rest.model.BlueOrganization;
import io.jenkins.blueocean.rest.model.BlueScmConfig;
import io.jenkins.blueocean.service.embedded.rest.OrganizationImpl;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import jenkins.branch.MultiBranchProject;
import jenkins.branch.OrganizationFolder;
import jenkins.model.Jenkins;
Expand All @@ -45,23 +51,21 @@
import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject;
import org.junit.After;
import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.Test;
import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.TestExtension;
import org.mockito.MockedStatic;
import org.mockito.Mockito;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.*;

/**
* @author Vivek Pandey
*/
public class GithubPipelineCreateRequestTest extends GithubMockBase {

@ClassRule
public static BuildWatcher watcher = new BuildWatcher();

@Override
@After
public void tearDown() {
Expand Down Expand Up @@ -377,6 +381,18 @@ public void testOrgFolderIndexing() throws Exception {
.build(Map.class);

assertNotNull(map);
for (var f : j.jenkins.allItems(ComputedFolder.class)) {
var c = f.getComputation();
// TODO indexing actually contacts github.com, and hangs due to rate limits
c.doStop();
System.err.println(f + " ---%<---");
long p = 0;
while (!c.getLogText().isComplete()) {
p = c.getLogText().writeLogTo(p, System.err);
}
System.err.println(f + " --->%---");
}
j.waitUntilNoActivity();
}

public static class TestOrganizationFolder extends OrganizationFolderPipelineImpl {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import hudson.model.ParametersAction;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.Project;
import hudson.model.Queue;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.StringParameterDefinition;
Expand Down Expand Up @@ -547,6 +548,10 @@ public void testPipelineQueue() throws Exception {
b2.doStop();
j.assertBuildStatus(Result.ABORTED, j.waitForCompletion(b1));
j.assertBuildStatus(Result.ABORTED, j.waitForCompletion(b2));
for (Queue.Item i : j.jenkins.getQueue().getItems()) {
j.jenkins.getQueue().cancel(i);
}
j.waitUntilNoActivity();
}

@Test
Expand Down

0 comments on commit 104e940

Please sign in to comment.