HEX
Server: Apache/2.4.59 (Debian)
System: Linux keymana 4.19.0-21-cloud-amd64 #1 SMP Debian 4.19.249-2 (2022-06-30) x86_64
User: lijunjie (1003)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //home/lijunjie/swoole-cli/swoole-src-4.8.13/tests/swoole_timer/info.phpt
--TEST--
swoole_timer: list
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc'; ?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';
$timers = [];
for ($c = 1000; $c--;) {
    $msec = mt_rand(100, 500);
    $timers[Swoole\Timer::after($msec, function () { })] = $msec;
}
foreach (Swoole\Timer::list() as $timer_id) {
    $info = Swoole\Timer::info($timer_id);
    time_approximate($timers[$timer_id], $info['exec_msec']);
    Assert::same($info['interval'], 0);
    Assert::same($info['round'], 0);
    Assert::false($info['removed']);
}
Swoole\Timer::tick(1, function (int $timer_id) {
    // tick
    $info = Swoole\Timer::info($timer_id);
    Assert::greaterThan($info['interval'], 0);
    Assert::same($info['round'], 0);
    Assert::false($info['removed']);
    // remove
    Swoole\Timer::clear($timer_id);
    $info = Swoole\Timer::info($timer_id);
    Assert::true($info['removed']);
    // after
    $info = Swoole\Timer::info(Swoole\Timer::after(1, function () { }));
    Assert::greaterThan($info['exec_msec'], 0);
    Assert::same($info['interval'], 0);
    Assert::same($info['round'], 1); // next round
    Assert::false($info['removed']);
});
Swoole\Event::wait();
echo "DONE\n";
?>
--EXPECT--
DONE