2525
2626package org .jenkinsci .plugins .github_branch_source ;
2727
28+ import static java .util .concurrent .TimeUnit .MILLISECONDS ;
29+ import static java .util .concurrent .TimeUnit .MINUTES ;
2830import static org .junit .Assert .assertEquals ;
2931
3032import java .io .IOException ;
3436import jenkins .scm .api .SCMHeadEvent ;
3537import jenkins .scm .api .SCMSourceEvent ;
3638import org .apache .commons .io .IOUtils ;
39+ import org .awaitility .Awaitility ;
3740import org .jenkinsci .plugins .github .extension .GHSubscriberEvent ;
3841import org .junit .AfterClass ;
3942import org .junit .Before ;
@@ -55,7 +58,7 @@ public class EventsTest {
5558
5659 @ BeforeClass
5760 public static void setupDelay () {
58- GitHubSCMSource .setEventDelaySeconds (1 );
61+ GitHubSCMSource .setEventDelaySeconds (0 ); // fire immediately without delay
5962 }
6063
6164 @ Before
@@ -188,7 +191,11 @@ private GHSubscriberEvent createEvent(String eventPayloadFile) throws IOExceptio
188191 private void waitAndAssertReceived (boolean received ) throws InterruptedException {
189192 long watermark = SCMEvents .getWatermark ();
190193 // event will be fired by subscriber at some point
191- SCMEvents .awaitOne (watermark , 1200 , TimeUnit .MILLISECONDS );
194+ SCMEvents .awaitOne (watermark , received ? 20 : 200 , TimeUnit .MILLISECONDS );
195+
196+ if (received ) {
197+ TestSCMEventListener .awaitUntilReceived ();
198+ }
192199
193200 assertEquals (
194201 "Event should have " + ((!received ) ? "not " : "" ) + "been received" ,
@@ -223,5 +230,12 @@ public static boolean didReceive() {
223230 public static void setReceived (boolean received ) {
224231 eventReceived = received ;
225232 }
233+
234+ public static void awaitUntilReceived () {
235+ Awaitility .await ()
236+ .pollInterval (10 , MILLISECONDS )
237+ .atMost (1 , MINUTES )
238+ .until (() -> eventReceived );
239+ }
226240 }
227241}
0 commit comments