1 #include "test_core.h"
2 #include "swoole_util.h"
3 
TEST(time,get_ms)4 TEST(time, get_ms) {
5     const int us = 3000;
6     long ms1 = swoole::time<std::chrono::milliseconds>();
7     usleep(us);
8     long ms2 = swoole::time<std::chrono::milliseconds>();
9     EXPECT_GE(ms2 - ms1, us / 1000);
10 }
11 
TEST(time,get_ms_steady)12 TEST(time, get_ms_steady) {
13     const int us = 3000;
14     long ms1 = swoole::time<std::chrono::milliseconds>(true);
15     usleep(us);
16     long ms2 = swoole::time<std::chrono::milliseconds>(true);
17     EXPECT_GE(ms2 - ms1, us / 1000);
18 }
19 
TEST(time,get_seconds)20 TEST(time, get_seconds) {
21     long sec1 = swoole::time<std::chrono::seconds>();
22     time_t sec2 = time(NULL);
23     ASSERT_TRUE(sec1 == sec2 or sec1 == sec2 - 1);
24 }
25