Skip to content

Commit be74a63

Browse files
committed
* fix test stability2
1 parent ee1ecab commit be74a63

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

tests/await/069-await_manual_vs_timeout_cancel.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ suspend();
7171
$race_coroutine->cancel(new \Async\CancellationException("Manual wins"));
7272

7373
try {
74-
$result = await($race_coroutine, timeout(1)); // Should get manual cancel, not timeout
74+
$result = await($race_coroutine, timeout(1000)); // Should get manual cancel, not timeout
7575
echo "race await should not succeed\n";
7676
} catch (\Async\CancellationException $e) {
7777
echo "race cancellation caught: " . get_class($e) . ": " . $e->getMessage() . "\n";

tests/socket_ext/002-socket_recv_send_async.phpt

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ use function Async\delay;
1616
echo "Start\n";
1717

1818
$port = null;
19+
$output = [];
1920

2021
// Server coroutine
21-
$server = spawn(function() use (&$port) {
22+
$server = spawn(function() use (&$port, &$output) {
2223
echo "Server: creating socket\n";
2324
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
2425
socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1);
@@ -30,40 +31,47 @@ $server = spawn(function() use (&$port) {
3031
echo "Server: listening on port $port\n";
3132

3233
$client = socket_accept($socket);
33-
echo "Server: client connected\n";
34+
$output[] = "Server: client connected";
3435

3536
$buffer = '';
3637
$bytes = socket_recv($client, $buffer, 1024, 0);
37-
echo "Server: received $bytes bytes: '$buffer'\n";
38+
$output[] = "Server: received $bytes bytes: '$buffer'";
3839

3940
$sent = socket_send($client, "Response from server", 20, 0);
40-
echo "Server: sent $sent bytes\n";
41+
$output[] = "Server: sent $sent bytes";
4142

4243
socket_close($client);
4344
socket_close($socket);
4445
});
4546

4647
// Client coroutine
47-
$client = spawn(function() use (&$port) {
48+
$client = spawn(function() use (&$port, &$output) {
4849
while ($port === null) {
4950
delay(1);
5051
}
5152

52-
echo "Client: connecting\n";
53+
$output[] = "Client: connecting";
5354
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
5455
socket_connect($socket, '127.0.0.1', $port);
5556

5657
$sent = socket_send($socket, "Request from client", 19, 0);
57-
echo "Client: sent $sent bytes\n";
58+
$output[] = "Client: sent $sent bytes";
5859

5960
$buffer = '';
6061
$bytes = socket_recv($socket, $buffer, 1024, 0);
61-
echo "Client: received $bytes bytes: '$buffer'\n";
62+
$output[] = "Client: received $bytes bytes: '$buffer'";
6263

6364
socket_close($socket);
6465
});
6566

6667
awaitAll([$server, $client]);
68+
69+
// Sort output for deterministic results
70+
sort($output);
71+
foreach ($output as $message) {
72+
echo $message . "\n";
73+
}
74+
6775
echo "End\n";
6876

6977
?>
@@ -72,9 +80,9 @@ Start
7280
Server: creating socket
7381
Server: listening on port %d
7482
Client: connecting
75-
Server: client connected
83+
Client: received 20 bytes: 'Response from server'
7684
Client: sent 19 bytes
85+
Server: client connected
7786
Server: received 19 bytes: 'Request from client'
7887
Server: sent 20 bytes
79-
Client: received 20 bytes: 'Response from server'
8088
End

0 commit comments

Comments
 (0)