7
7
8
8
class PubNubContext
9
9
{
10
+ protected int $ retryLimit = 12 ;
11
+
10
12
/** @BeforeScenario */
11
13
public function before (BeforeScenarioScope $ scope ): void
12
14
{
15
+ $ this ->waitForServer ();
13
16
$ ch = curl_init ();
14
17
curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , 1 );
15
18
curl_setopt ($ ch , CURLOPT_CONNECTTIMEOUT , 10 );
@@ -27,6 +30,7 @@ public function before(BeforeScenarioScope $scope): void
27
30
/** @AfterScenario */
28
31
public function after (AfterScenarioScope $ scope ): void
29
32
{
33
+ $ this ->waitForServer ();
30
34
$ ch = curl_init ();
31
35
curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , 1 );
32
36
curl_setopt ($ ch , CURLOPT_CONNECTTIMEOUT , 10 );
@@ -39,4 +43,30 @@ public function after(AfterScenarioScope $scope): void
39
43
}
40
44
curl_close ($ ch );
41
45
}
46
+
47
+ protected function waitForServer ()
48
+ {
49
+
50
+ for ($ i = 1 ; $ i <= $ this ->retryLimit ; $ i ++) {
51
+ print ("Trying to connect ( $ i/ $ this ->retryLimit )... \n" );
52
+ $ ch = curl_init ();
53
+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , 1 );
54
+ curl_setopt ($ ch , CURLOPT_CONNECTTIMEOUT , 10 );
55
+ curl_setopt ($ ch , CURLOPT_TIMEOUT , 10 );
56
+ curl_setopt ($ ch , CURLOPT_URL , 'http://localhost:8090 ' );
57
+ curl_exec ($ ch );
58
+ $ err = curl_error ($ ch );
59
+ if ($ err === "" ) {
60
+ print ("Server started \n" );
61
+ break ;
62
+ }
63
+ print ($ err . "\n" );
64
+
65
+ if ($ i === $ this ->retryLimit ) {
66
+ print ("Server not started \n" );
67
+ exit (1 );
68
+ }
69
+ sleep ($ i );
70
+ }
71
+ }
42
72
}
0 commit comments