@@ -11,12 +11,19 @@ class RemoteSimpleTest extends \Codeception\TestCase\Test
11
11
12
12
public function _before ()
13
13
{
14
+ Co::setDefaultOptions (['concurrency ' => 0 ]);
14
15
}
15
16
16
17
public function _after ()
17
18
{
18
19
}
19
20
21
+ private function assertInRange ($ min , $ actual , $ max )
22
+ {
23
+ $ this ->assertGreaterThanOrEqual ($ min , $ actual );
24
+ $ this ->assertLessThanOrEqual ($ max , $ actual );
25
+ }
26
+
20
27
private static function curlInitWith ($ url , array $ params = [])
21
28
{
22
29
$ ch = curl_init ();
@@ -29,17 +36,112 @@ private static function curlInitWith($url, array $params = [])
29
36
return $ ch ;
30
37
}
31
38
32
- public function testDownload ( )
39
+ private function curlsInitWith ( $ n , $ url , array $ params = [] )
33
40
{
34
- $ ch = self ::curlInitWith ('http://localhost:8080/upload_form.php ' );
35
- Co::wait ($ ch );
36
- $ this ->assertEquals (200 , curl_getinfo ($ ch , CURLINFO_HTTP_CODE ));
41
+ $ curls = [];
42
+ for ($ i = 0 ; $ i < $ n ; ++$ i ) {
43
+ $ curls [] = $ this ->curlInitWith ($ url , $ params );
44
+ }
45
+ return $ curls ;
37
46
}
38
47
39
- public function testRunSecure ( )
48
+ private function curlAssert200OK ( $ ch )
40
49
{
41
- $ ch = self ::curlInitWith ('https://localhost:8081/upload_form.php ' );
42
- Co::wait ($ ch );
43
50
$ this ->assertEquals (200 , curl_getinfo ($ ch , CURLINFO_HTTP_CODE ));
44
51
}
52
+
53
+ private function curlsAssert200OK (array $ curls )
54
+ {
55
+ foreach ($ curls as $ ch ) {
56
+ $ this ->assertEquals (200 , curl_getinfo ($ ch , CURLINFO_HTTP_CODE ));
57
+ }
58
+ }
59
+
60
+ public function testSimple ()
61
+ {
62
+ Co::wait ($ ch = $ this ->curlInitWith ('http://localhost:8080/upload_form.php ' ));
63
+ $ this ->curlAssert200OK ($ ch );
64
+ }
65
+
66
+ public function testSimpleSecure ()
67
+ {
68
+ Co::wait ($ ch = $ this ->curlInitWith ('https://localhost:8081/upload_form.php ' ));
69
+ $ this ->curlAssert200OK ($ ch );
70
+ }
71
+
72
+ public function testDelayed ()
73
+ {
74
+ $ start = microtime (true );
75
+ Co::wait ($ ch = $ this ->curlInitWith ('http://localhost:8080/fast_hello.php ' ));
76
+ $ end = microtime (true );
77
+ $ this ->curlAssert200OK ($ ch );
78
+ $ this ->assertInRange (0.1 , $ end - $ start , 0.2 );
79
+ }
80
+
81
+ public function testDelayedSecure ()
82
+ {
83
+ $ start = microtime (true );
84
+ Co::wait ($ ch = $ this ->curlInitWith ('https://localhost:8081/fast_hello.php ' ));
85
+ $ end = microtime (true );
86
+ $ this ->curlAssert200OK ($ ch );
87
+ $ this ->assertInRange (0.11 , $ end - $ start , 0.21 );
88
+ }
89
+
90
+ public function testDelayedGroupSingle ()
91
+ {
92
+ $ start = microtime (true );
93
+ Co::wait ($ chs = $ this ->curlsInitWith (5 , 'http://localhost:8080/fast_hello.php ' ));
94
+ $ end = microtime (true );
95
+ $ this ->curlsAssert200OK ($ chs );
96
+ $ this ->assertInRange (0.12 , $ end - $ start , 0.22 );
97
+ }
98
+
99
+ public function testDelayedGroupSingleSecure ()
100
+ {
101
+ $ start = microtime (true );
102
+ Co::wait ($ chs = $ this ->curlsInitWith (5 , 'https://localhost:8081/fast_hello.php ' ));
103
+ $ end = microtime (true );
104
+ $ this ->curlsAssert200OK ($ chs );
105
+ $ this ->assertInRange (0.12 , $ end - $ start , 0.22 );
106
+ }
107
+
108
+ public function testDelayedGroupDouble ()
109
+ {
110
+ $ start = microtime (true );
111
+ Co::wait ($ chs = $ this ->curlsInitWith (10 , 'http://localhost:8080/fast_hello.php ' ));
112
+ $ end = microtime (true );
113
+ $ this ->curlsAssert200OK ($ chs );
114
+ $ this ->assertInRange (0.28 , $ end - $ start , 0.38 );
115
+ }
116
+
117
+ public function testDelayedGroupDoubleSecure ()
118
+ {
119
+ $ start = microtime (true );
120
+ Co::wait ($ chs = $ this ->curlsInitWith (10 , 'https://localhost:8081/fast_hello.php ' ));
121
+ $ end = microtime (true );
122
+ $ this ->curlsAssert200OK ($ chs );
123
+ $ this ->assertInRange (0.32 , $ end - $ start , 0.42 );
124
+ }
125
+
126
+ public function testDelayedGroupDoubleAtOnce ()
127
+ {
128
+ $ start = microtime (true );
129
+ Co::wait ($ chs = $ this ->curlsInitWith (10 , 'http://localhost:8080/fast_hello.php ' ), [
130
+ 'concurrency ' => 0 ,
131
+ ]);
132
+ $ end = microtime (true );
133
+ $ this ->curlsAssert200OK ($ chs );
134
+ $ this ->assertInRange (0.28 , $ end - $ start , 0.38 );
135
+ }
136
+
137
+ public function testDelayedGroupDoubleAtOnceSecure ()
138
+ {
139
+ $ start = microtime (true );
140
+ Co::wait ($ chs = $ this ->curlsInitWith (10 , 'https://localhost:8081/fast_hello.php ' ), [
141
+ 'concurrency ' => 0 ,
142
+ ]);
143
+ $ end = microtime (true );
144
+ $ this ->curlsAssert200OK ($ chs );
145
+ $ this ->assertInRange (0.32 , $ end - $ start , 0.42 );
146
+ }
45
147
}
0 commit comments