Skip to content

Commit ae2c2ac

Browse files
author
Mikhail Galanin
committed
fixed test
1 parent c29197d commit ae2c2ac

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

sapi/fpm/tests/listen-socket-closed-on-exec.phpt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,31 @@ pm.status_path = /status
2424
env[PATH] = $PATH
2525
EOT;
2626

27-
2827
$code = <<<'EOT'
2928
<?php
3029
31-
echo "My sockets (expect to see 2 of them):\n";
30+
$fpmPort = $_GET['fpm_port'];
31+
32+
echo "My sockets (expect to see 2 of them - one ESTABLISHED and one LISTEN):\n";
3233
3334
$mypid = getmypid();
34-
$ph = popen("/bin/sh -c 'lsof -Pn -p$mypid' 2>&1 | grep TCP", 'r');
35+
$ph = popen("/bin/sh -c 'lsof -Pn -p$mypid' 2>&1 | grep TCP | grep '127.0.0.1:$fpmPort'", 'r');
3536
echo stream_get_contents($ph);
3637
pclose($ph);
3738
3839
echo "\n\n";
3940
41+
/*
42+
We expect that both LISTEN (inherited from the master process) and ACCEPTED (ESTABLISHED)
43+
have F_CLOEXEC and should not appear in the created process.
44+
45+
We grep out sockets from non-FPM port, because they may appear in the environment,
46+
e.g. PHP-FPM can inherit them from the test-runner. We cannot control the runner
47+
but we test how the FPM behaves.
48+
*/
49+
4050
echo "Sockets after exec(), expected to be empty:\n";
41-
$ph = popen("/bin/sh -c 'lsof -Pn -p\$\$' 2>&1 | grep TCP", 'r');
51+
$ph = popen("/bin/sh -c 'lsof -Pn -p\$\$' 2>&1 | grep TCP | grep '127.0.0.1:$fpmPort'", 'r');
4252
var_dump(stream_get_contents($ph));
4353
pclose($ph);
4454

@@ -47,7 +57,7 @@ EOT;
4757
$tester = new FPM\Tester($cfg, $code);
4858
$tester->start();
4959
$tester->expectLogStartNotices();
50-
$tester->request()->printBody();
60+
$tester->request(query: 'fpm_port='.$tester->getPort())->printBody();
5161
usleep(100000);
5262
//$tester->status($expectedStatusData, '{{ADDR[status]}}');
5363
$tester->terminate();
@@ -57,7 +67,9 @@ $tester->close();
5767
?>
5868
Done
5969
--EXPECTF--
60-
My sockets (expect to see 2 of them):
70+
My sockets (expect to see 2 of them - one ESTABLISHED and one LISTEN):
71+
%S 127.0.0.1:%d->127.0.0.1:%d (ESTABLISHED)
72+
%S 127.0.0.1:%d (LISTEN)
6173

6274

6375
Sockets after exec(), expected to be empty:

0 commit comments

Comments
 (0)