@@ -82,13 +82,33 @@ public function connectionToTcpServerShouldFailIfFileDescriptorsAreExceeded()
82
82
83
83
$ connector = new TcpConnector ($ loop );
84
84
85
- $ ulimit = exec ('ulimit -n 2>&1 ' );
86
- if ($ ulimit < 1 ) {
85
+ /** @var string[] $_ */
86
+ /** @var int $exit */
87
+ $ ulimit = exec ('ulimit -n 2>&1 ' , $ _ , $ exit );
88
+ if ($ exit !== 0 || $ ulimit < 1 ) {
87
89
$ this ->markTestSkipped ('Unable to determine limit of open files (ulimit not available?) ' );
88
90
}
89
91
92
+ $ memory = ini_get ('memory_limit ' );
93
+ if ($ memory === '-1 ' ) {
94
+ $ memory = PHP_INT_MAX ;
95
+ } elseif (preg_match ('/^\d+G$/i ' , $ memory )) {
96
+ $ memory = ((int ) $ memory ) * 1024 * 1024 * 1024 ;
97
+ } elseif (preg_match ('/^\d+M$/i ' , $ memory )) {
98
+ $ memory = ((int ) $ memory ) * 1024 * 1024 ;
99
+ } elseif (preg_match ('/^\d+K$/i ' , $ memory )) {
100
+ $ memory = ((int ) $ memory ) * 1024 ;
101
+ }
102
+
103
+ // each file descriptor takes ~600 bytes of memory, so skip test if this would exceed memory_limit
104
+ if ($ ulimit * 600 > $ memory ) {
105
+ $ this ->markTestSkipped ('Test requires ~ ' . round ($ ulimit * 600 / 1024 / 1024 ) . '/ ' . round ($ memory / 1024 / 1024 ) . ' MiB memory with ' . $ ulimit . ' file descriptors ' );
106
+ }
107
+
90
108
// dummy rejected promise to make sure autoloader has initialized all classes
91
- $ foo = new Promise (function () { throw new \RuntimeException ('dummy ' ); });
109
+ class_exists ('React\Socket\SocketServer ' , true );
110
+ class_exists ('PHPUnit\Framework\Error\Warning ' , true );
111
+ new Promise (function () { throw new \RuntimeException ('dummy ' ); });
92
112
93
113
// keep creating dummy file handles until all file descriptors are exhausted
94
114
$ fds = array ();
0 commit comments