From 084a76a4155222c06bac598fcd918185c418be8d Mon Sep 17 00:00:00 2001 From: Dmitry_Platonov Date: Wed, 13 Jul 2022 15:44:09 +0300 Subject: [PATCH] fix flickering and improve speed in EventsTest --- pom.xml | 12 ++++++++++++ .../github_branch_source/EventsTest.java | 18 ++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3aafb5737..6779e248c 100644 --- a/pom.xml +++ b/pom.xml @@ -115,6 +115,18 @@ 589.vb_a_b_4a_a_8c443c test + + org.awaitility + awaitility + 4.2.0 + test + + + org.hamcrest + hamcrest + + + io.jenkins.plugins okhttp-api diff --git a/src/test/java/org/jenkinsci/plugins/github_branch_source/EventsTest.java b/src/test/java/org/jenkinsci/plugins/github_branch_source/EventsTest.java index 7416da7f4..13f2fbfd2 100644 --- a/src/test/java/org/jenkinsci/plugins/github_branch_source/EventsTest.java +++ b/src/test/java/org/jenkinsci/plugins/github_branch_source/EventsTest.java @@ -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; @@ -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; @@ -55,7 +58,7 @@ public class EventsTest { @BeforeClass public static void setupDelay() { - GitHubSCMSource.setEventDelaySeconds(1); + GitHubSCMSource.setEventDelaySeconds(0); // fire immediately without delay } @Before @@ -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", @@ -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); + } } }