[php-src] PR #22724: CI: fix unstable test \ext\sockets\tests\socket_recvfrom_afpacket_no_port.phpt
| From: | LamentXU123 | Date: | Tue, 14 Jul 2026 09:25:16 +0000 |
| Subject: | [php-src] PR #22724: CI: fix unstable test \ext\sockets\tests\socket_recvfrom_afpacket_no_port.phpt | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-37035@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/22724
Author: LamentXU123
Fix flaky CI: https://github.com/php/php-src/actions/runs/29266463698/job/86873055452
When investigating, I've noticed that similar tests does not have this issue. Only
socket_recvfrom_afpacket_no_port.phpt is flaky. Which makes me discover a shared logic
in tests:
https://github.com/php/php-src/blob/master/ext/sockets/tests/socket_sendto_recvfrom_afpacket_malformed.phpt#L28-L41
```php
<?php
function recv_matching(Socket $s, string $header, int $maxlen = 65536, ?string &$addr = null,
&$port = null): string|false {
socket_set_nonblock($s);
$deadline = microtime(true) + 5.0;
while (microtime(true) < $deadline) {
$bytes = @socket_recvfrom($s, $buf, $maxlen, 0, $addr, $port);
if ($bytes !== false && is_string($buf) && str_starts_with($buf, $header)) {
return $buf;
}
if ($bytes === false) {
usleep(1000);
}
}
return false;
}
```
This allows the test to wait for a frame matching its own Ethernet header before asserting the
returned address, so it no longer depends on incidental packet ordering. ETH_P_ALL sockets on
loopback can observe unrelated localhost traffic.
And this single flack test donesn't have that logic. Let's add them.