Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/test_4_function_invocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ function post(string $url, array $params)

$body = ['Hello' => 'From Bref!'];

waitForPort('127.0.0.1', 8080);

try {
$response = post('http://127.0.0.1:8080/2015-03-31/functions/function/invocations', $body);
$response = json_decode($response, true, 512, JSON_THROW_ON_ERROR);
Expand Down
2 changes: 2 additions & 0 deletions tests/test_5_fpm_invocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ function post(string $url, string $body)

$body = file_get_contents(__DIR__ . '/test_5_event.json');

waitForPort('127.0.0.1', 8080);

try {
$response = post('http://127.0.0.1:8080/2015-03-31/functions/function/invocations', $body);
$response = json_decode($response, true, 512, JSON_THROW_ON_ERROR);
Expand Down
2 changes: 2 additions & 0 deletions tests/test_6_console_invocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ function post(string $url, string $param)

$body = '"From Bref"';

waitForPort('127.0.0.1', 8080);

try {
$response = post('http://127.0.0.1:8080/2015-03-31/functions/function/invocations', $body);
$response = json_decode($response, true, 512, JSON_THROW_ON_ERROR);
Expand Down
2 changes: 2 additions & 0 deletions tests/test_7_custom_ini_scan_dir.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ function post(string $url, string $params)

$body = 'list_extensions';

waitForPort('127.0.0.1', 8080);

try {
$response = post('http://127.0.0.1:8080/2015-03-31/functions/function/invocations', $body);
$response = json_decode($response, true, 512, JSON_THROW_ON_ERROR);
Expand Down
19 changes: 19 additions & 0 deletions tests/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,22 @@ function success(string $message): void
}
exit(1);
}

/**
* Wait for a port to be available (useful for QEMU-emulated containers that start slowly).
*/
function waitForPort(string $host, int $port, int $timeoutSeconds = 5): void
{
$start = time();
while (true) {
$socket = @fsockopen($host, $port, $errno, $errstr, 1);
if ($socket !== false) {
fclose($socket);
return;
}
if (time() - $start >= $timeoutSeconds) {
error("Timeout waiting for $host:$port to be available");
}
usleep(100000); // 100ms
}
}