summaryrefslogtreecommitdiff
path: root/ext/ftp/tests
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-10-22 12:53:57 +0200
committerNikita Popov <nikita.ppv@gmail.com>2020-10-23 10:48:21 +0200
commit08eb917fd5d5f62eb2c3403ac41e576325a0b519 (patch)
tree7a2ef2badce2447a436411c2ceb05ad67ed6bf11 /ext/ftp/tests
parenta876577ebeec3b96da1ea0c2ec2259800e4300e5 (diff)
downloadphp-git-08eb917fd5d5f62eb2c3403ac41e576325a0b519.tar.gz
Use ephemeral port in ftp tests
And enable them to run in parallel.
Diffstat (limited to 'ext/ftp/tests')
-rw-r--r--ext/ftp/tests/CONFLICTS1
-rw-r--r--ext/ftp/tests/server.inc37
2 files changed, 13 insertions, 25 deletions
diff --git a/ext/ftp/tests/CONFLICTS b/ext/ftp/tests/CONFLICTS
deleted file mode 100644
index 254defddb5..0000000000
--- a/ext/ftp/tests/CONFLICTS
+++ /dev/null
@@ -1 +0,0 @@
-server
diff --git a/ext/ftp/tests/server.inc b/ext/ftp/tests/server.inc
index 0d0fea63c4..33e32ac1bb 100644
--- a/ext/ftp/tests/server.inc
+++ b/ext/ftp/tests/server.inc
@@ -4,21 +4,15 @@ $socket = null;
$errno = 0;
$context = stream_context_create(array('ssl' => array('local_cert' => dirname(__FILE__).'/cert.pem')));
-for ($i=0; $i<10 && !$socket; ++$i) {
- $port = rand(50000, 65535);
-
- $socket = @stream_socket_server("tcp://127.0.0.1:$port", $errno, $errstr, STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context);
-}
-//set anther random port that is not the same as $port
-do{
- $pasv_port = rand(50000, 65535);
-}while($pasv_port == $port);
-
+$socket = stream_socket_server("tcp://127.0.0.1:0", $errno, $errstr, STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context);
if (!$socket) {
echo "$errstr ($errno)\n";
die("could not start/bind the ftp server\n");
}
+$socket_name = stream_socket_get_name($socket, false);
+$port = (int) substr($socket_name, strrpos($socket_name, ':') + 1);
+
$pid = pcntl_fork();
if ($pid) {
@@ -402,25 +396,20 @@ if ($pid) {
$i=0;
if (empty($bug73457)) {
- do {
- if (!empty($ssl)) {
- $soc = @stream_socket_server("tcp://127.0.0.1:$pasv_port", $errno, $errstr, STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context);
- } else {
- $soc = @stream_socket_server("tcp://127.0.0.1:$pasv_port");
- }
- /* Could bind port, Try another port */
- if (!$soc) {
- $pasv_port = rand(50000, 65535);
- }
- $i++;
- } while ($i<10 && !$soc);
-
+ if (!empty($ssl)) {
+ $soc = stream_socket_server("tcp://127.0.0.1:0", $errno, $errstr, STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context);
+ } else {
+ $soc = stream_socket_server("tcp://127.0.0.1:0");
+ }
if (!$soc) {
echo "$errstr ($errno)\n";
die("could not bind passive port\n");
}
+
+ $soc_name = stream_socket_get_name($soc, false);
+ $pasv_port = (int) substr($socket_name, strrpos($soc_name, ':') + 1);
} else {
- $pasv_port=1234;
+ $pasv_port = 1234;
}
$p2 = $pasv_port % ((int) 1 << 8);