30
30
import java .util .ArrayList ;
31
31
import java .util .Collections ;
32
32
import java .util .List ;
33
+
34
+ import static java .util .concurrent .TimeUnit .SECONDS ;
33
35
import static org .junit .Assert .*;
36
+
37
+ import org .awaitility .Awaitility ;
34
38
import org .junit .Rule ;
35
39
import org .junit .Test ;
36
40
import hudson .tasks .Builder ;
@@ -51,7 +55,7 @@ public class BuildTriggerTest {
51
55
public LoggerRule logging = new LoggerRule ().record (Run .class , Level .FINE );
52
56
53
57
@ Test
54
- public void testParentProjectTrigger () throws Exception {
58
+ public void testParentProjectTrigger () throws Exception {
55
59
FreeStyleProject downstream = r .createFreeStyleProject ("downstream" );
56
60
MatrixProject upstream = r .createProject (MatrixProject .class , "upstream" );
57
61
List <ParameterDefinition > definition = new ArrayList <ParameterDefinition >();
@@ -64,16 +68,16 @@ public void testParentProjectTrigger() throws Exception{
64
68
params .add (new CurrentBuildParameters ());
65
69
BuildTrigger triggerBuilder = new BuildTrigger (new BuildTriggerConfig ("downstream" , ResultCondition .SUCCESS , false , null , params , false ));
66
70
upstream .getPublishersList ().add (triggerBuilder );
71
+
67
72
r .buildAndAssertSuccess (upstream );
68
- r .waitUntilNoActivity ();
69
- FreeStyleBuild downstreamBuild = downstream .getLastBuild ();
70
- assertNotNull ("Downstream job should be triggered" , downstreamBuild );
71
- String project = downstreamBuild .getCause (Cause .UpstreamCause .class ).getUpstreamProject ();
73
+ Awaitility .await ().pollInterval (1 , SECONDS ).atMost (10 , SECONDS ).until (() -> downstream .getLastBuild () != null );
74
+
75
+ String project = downstream .getLastBuild ().getCause (Cause .UpstreamCause .class ).getUpstreamProject ();
72
76
assertEquals ("Build should be triggered by matrix project." , "upstream" , project );
73
77
}
74
78
75
79
@ Test
76
- public void testChildProjectsTrigger () throws Exception {
80
+ public void testChildProjectsTrigger () throws Exception {
77
81
MatrixProject upstream = r .createProject (MatrixProject .class , "upstream" );
78
82
FreeStyleProject downstream = r .createFreeStyleProject ("downstream" );
79
83
0 commit comments