Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Oct 29, 2024
1 parent b46ed22 commit f133584
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
8 changes: 6 additions & 2 deletions scripts/make.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#!/bin/sh -e
#!/bin/sh
__CURRENT_DIR__=$(cd "$(dirname "$0")";pwd)
__DIR__=$(cd "$(dirname "${__CURRENT_DIR__}")";pwd)
__HAVE_ZTS__=$(php -v|grep ZTS)

COMPILE_PARAMS="--enable-openssl \
--enable-sockets \
--enable-mysqlnd \
--enable-swoole-curl \
--enable-cares \
--enable-swoole-thread \
--enable-swoole-pgsql \
--with-swoole-odbc=unixODBC,/usr \
--enable-swoole-sqlite"

if [ -n "$__HAVE_ZTS__" ]; then
COMPILE_PARAMS="$COMPILE_PARAMS --enable-swoole-thread"
fi

if [ "$(uname | grep -i darwin)"x != ""x ]; then
CPU_COUNT="$(sysctl -n machdep.cpu.core_count)"
Expand Down
7 changes: 7 additions & 0 deletions tests/include/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -865,3 +865,10 @@ function get_thread_name(): string
{
return trim(file_get_contents('/proc/' . posix_getpid() . '/task/' . \Swoole\Thread::getNativeId() . '/comm'));
}

function mkdir_if_not_exists(string $string): void
{
if (!is_dir($string)) {
mkdir($string, 0777, true);
}
}
2 changes: 1 addition & 1 deletion tests/include/skipif.inc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function swoole_color(string $content, int $color): string
function skip(string $reason, bool $is_skip = true, int $color = SWOOLE_COLOR_YELLOW)
{
if ($is_skip) {
exit('skip ' . swoole_color($reason, $color));
exit('skip ' . swoole_color($reason, $color) . "\n");
}
}

Expand Down
32 changes: 32 additions & 0 deletions tests/swoole_coroutine_system/getaddrinfo_timeout.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
swoole_coroutine_system: getaddrinfo timeout
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc';
skip_if_offline();
skip_if_not_root();
?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';
$tmpdir = '/tmp/' . uniqid();

mkdir_if_not_exists($tmpdir . '/etc');
chroot($tmpdir);
if (!is_file('/etc/resolv.conf')) {
file_put_contents('/etc/resolv.conf', "nameserver 192.168.8.8\noptions timeout:1 retry:1\n");
}

Co\run(static function () {
$res = Swoole\Coroutine\System::getaddrinfo(
domain: 'swoole-non-existent-domain',
protocol: 0,
service: '',
timeout: 0.5,
);
Assert::false($res);
Assert::eq(swoole_last_error(), SWOOLE_ERROR_CO_TIMEDOUT);
echo "DONE\n";
});
?>
--EXPECT--
DONE

0 comments on commit f133584

Please sign in to comment.