Skip to content

Commit

Permalink
Merge pull request #589 from Pldi23/flakebusters
Browse files Browse the repository at this point in the history
fix flickering and improve speed in EventsTest
  • Loading branch information
jtnord authored Jul 15, 2022
2 parents e6f1105 + 084a76a commit 0c05abd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@
<version>589.vb_a_b_4a_a_8c443c</version> <!-- TODO until in BOM -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>4.2.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>okhttp-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

package org.jenkinsci.plugins.github_branch_source;

import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.MINUTES;
import static org.junit.Assert.assertEquals;

import java.io.IOException;
Expand All @@ -34,6 +36,7 @@
import jenkins.scm.api.SCMHeadEvent;
import jenkins.scm.api.SCMSourceEvent;
import org.apache.commons.io.IOUtils;
import org.awaitility.Awaitility;
import org.jenkinsci.plugins.github.extension.GHSubscriberEvent;
import org.junit.AfterClass;
import org.junit.Before;
Expand All @@ -55,7 +58,7 @@ public class EventsTest {

@BeforeClass
public static void setupDelay() {
GitHubSCMSource.setEventDelaySeconds(1);
GitHubSCMSource.setEventDelaySeconds(0); // fire immediately without delay
}

@Before
Expand Down Expand Up @@ -188,7 +191,11 @@ private GHSubscriberEvent createEvent(String eventPayloadFile) throws IOExceptio
private void waitAndAssertReceived(boolean received) throws InterruptedException {
long watermark = SCMEvents.getWatermark();
// event will be fired by subscriber at some point
SCMEvents.awaitOne(watermark, 1200, TimeUnit.MILLISECONDS);
SCMEvents.awaitOne(watermark, received ? 20 : 200, TimeUnit.MILLISECONDS);

if (received) {
TestSCMEventListener.awaitUntilReceived();
}

assertEquals(
"Event should have " + ((!received) ? "not " : "") + "been received",
Expand Down Expand Up @@ -223,5 +230,12 @@ public static boolean didReceive() {
public static void setReceived(boolean received) {
eventReceived = received;
}

public static void awaitUntilReceived() {
Awaitility.await()
.pollInterval(10, MILLISECONDS)
.atMost(1, MINUTES)
.until(() -> eventReceived);
}
}
}

0 comments on commit 0c05abd

Please sign in to comment.