Skip to content

Commit

Permalink
Fix flakiness in BuildTriggerTest (#226)
Browse files Browse the repository at this point in the history
There was the possibility of a race condition where the queue was empty
but the downstream job not yet added to it, resulting in assertions being
check too early and fail.

Show in a CI run under heavy load, not something usual, but this change
should remove the possibility
  • Loading branch information
raul-arabaolaza authored Nov 11, 2021
1 parent d4a6fc1 commit b8f2425
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@
<artifactId>token-macro</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>4.1.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.Assert.*;

import org.awaitility.Awaitility;
import org.junit.Rule;
import org.junit.Test;
import hudson.tasks.Builder;
Expand All @@ -51,7 +55,7 @@ public class BuildTriggerTest {
public LoggerRule logging = new LoggerRule().record(Run.class, Level.FINE);

@Test
public void testParentProjectTrigger() throws Exception{
public void testParentProjectTrigger() throws Exception {
FreeStyleProject downstream = r.createFreeStyleProject("downstream");
MatrixProject upstream = r.createProject(MatrixProject.class, "upstream");
List<ParameterDefinition> definition = new ArrayList<ParameterDefinition>();
Expand All @@ -64,16 +68,16 @@ public void testParentProjectTrigger() throws Exception{
params.add(new CurrentBuildParameters());
BuildTrigger triggerBuilder = new BuildTrigger(new BuildTriggerConfig("downstream", ResultCondition.SUCCESS, false, null, params, false));
upstream.getPublishersList().add(triggerBuilder);

r.buildAndAssertSuccess(upstream);
r.waitUntilNoActivity();
FreeStyleBuild downstreamBuild = downstream.getLastBuild();
assertNotNull("Downstream job should be triggered", downstreamBuild);
String project = downstreamBuild.getCause(Cause.UpstreamCause.class).getUpstreamProject();
Awaitility.await().pollInterval(1, SECONDS).atMost(10, SECONDS).until(() -> downstream.getLastBuild() != null);

String project = downstream.getLastBuild().getCause(Cause.UpstreamCause.class).getUpstreamProject();
assertEquals("Build should be triggered by matrix project.", "upstream", project);
}

@Test
public void testChildProjectsTrigger() throws Exception{
public void testChildProjectsTrigger() throws Exception {
MatrixProject upstream = r.createProject(MatrixProject.class, "upstream");
FreeStyleProject downstream = r.createFreeStyleProject("downstream");

Expand Down

0 comments on commit b8f2425

Please sign in to comment.