From 6282da49729334ca0deea1119f94646664e4238e Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 7 Aug 2022 13:11:27 +0800 Subject: [PATCH] fix zm_sleep float bug and add test --- src/ZM/global_functions.php | 3 ++- tests/ZM/GlobalFunctionsTest.php | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ZM/global_functions.php b/src/ZM/global_functions.php index db16896b..23972eef 100644 --- a/src/ZM/global_functions.php +++ b/src/ZM/global_functions.php @@ -279,9 +279,10 @@ function get_onebot_target_id_name(string $message_type): string * * 与 {@link sleep()} 一致,只是增加了协程支持 * + * @param float|int $seconds 秒数(支持到1ms(0.001)) * @since 2.7.3 此函数不再返回 true */ -function zm_sleep(int $seconds = 1): void +function zm_sleep($seconds = 1): void { if (Coroutine::getCid() !== -1) { System::sleep($seconds); diff --git a/tests/ZM/GlobalFunctionsTest.php b/tests/ZM/GlobalFunctionsTest.php index 88abda5f..097eb2f4 100644 --- a/tests/ZM/GlobalFunctionsTest.php +++ b/tests/ZM/GlobalFunctionsTest.php @@ -76,4 +76,11 @@ class GlobalFunctionsTest extends TestCase { $this->assertEquals(['code' => 0, 'signal' => 0, 'output' => "foo\n"], zm_exec('echo foo')); } + + public function testZmSleep(): void + { + $starttime = microtime(true); + zm_sleep(0.001); + $this->assertGreaterThanOrEqual(0.001, microtime(true) - $starttime); + } }