Skip to content

Commit 173338a

Browse files
committed
fix tests 4 --filter=[core]
1 parent c849a1f commit 173338a

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

core-tests/src/core/base.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,14 +369,30 @@ TEST(base, spinlock) {
369369
}
370370

371371
TEST(base, futex) {
372-
sw_atomic_t value = 0;
372+
sw_atomic_t value = 1;
373373

374-
std::thread t1([&value]{
375-
ASSERT_EQ(sw_atomic_futex_wait(&value, 0.05), SW_ERR);
376-
ASSERT_EQ(sw_atomic_futex_wait(&value, 0.5), SW_OK);
374+
std::thread t1([&value] {
375+
DEBUG() << "wait 1\n";
376+
ASSERT_EQ(sw_atomic_futex_wait(&value, -1), SW_OK); // no wait
377+
value = 0;
378+
379+
DEBUG() << "wait 2\n";
380+
381+
ASSERT_EQ(sw_atomic_futex_wait(&value, 0.05), SW_ERR); // timed out
382+
ASSERT_EQ(sw_atomic_futex_wait(&value, 0.5), SW_OK); // success
383+
384+
DEBUG() << "wait 3\n";
385+
386+
value = 0;
387+
ASSERT_EQ(sw_atomic_futex_wait(&value, -1), SW_OK); // no timeout
377388
});
378389

379-
std::thread t2([&value]{
390+
std::thread t2([&value] {
391+
usleep(100000);
392+
DEBUG() << "wakeup 1\n";
393+
ASSERT_EQ(sw_atomic_futex_wakeup(&value, 1), 1);
394+
395+
DEBUG() << "wakeup 2\n";
380396
usleep(100000);
381397
ASSERT_EQ(sw_atomic_futex_wakeup(&value, 1), 1);
382398
});

core-tests/src/core/log.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,39 @@ TEST(log, level) {
1515
for (auto iter = processTypes.begin(); iter != processTypes.end(); iter++) {
1616
swoole_set_worker_type(*iter);
1717
sw_logger()->reset();
18+
19+
ASSERT_FALSE(sw_logger()->is_opened());
20+
21+
sw_logger()->set_level(999);
22+
ASSERT_EQ(sw_logger()->get_level(), SW_LOG_NONE);
23+
24+
sw_logger()->set_level(SW_LOG_DEBUG - 10);
25+
ASSERT_EQ(sw_logger()->get_level(), SW_LOG_DEBUG);
26+
1827
sw_logger()->set_level(SW_LOG_NOTICE);
1928
sw_logger()->open(file);
2029

30+
ASSERT_TRUE(sw_logger()->is_opened());
31+
32+
sw_logger()->put(SW_LOG_DEBUG, SW_STRL("hello no debug"));
33+
sw_logger()->put(SW_LOG_TRACE, SW_STRL("hello no trace"));
2134
sw_logger()->put(SW_LOG_INFO, SW_STRL("hello info"));
2235
sw_logger()->put(SW_LOG_NOTICE, SW_STRL("hello notice"));
2336
sw_logger()->put(SW_LOG_WARNING, SW_STRL("hello warning"));
2437

38+
sw_logger()->set_level(SW_LOG_DEBUG);
39+
sw_logger()->put(SW_LOG_DEBUG, SW_STRL("hello debug"));
40+
sw_logger()->put(SW_LOG_TRACE, SW_STRL("hello trace"));
41+
2542
auto content = file_get_contents(file);
2643

2744
sw_logger()->close();
2845
unlink(file);
2946

47+
ASSERT_FALSE(content->contains(SW_STRL("hello no debug")));
48+
ASSERT_FALSE(content->contains(SW_STRL("hello no trace")));
49+
ASSERT_TRUE(content->contains(SW_STRL("hello debug")));
50+
ASSERT_TRUE(content->contains(SW_STRL("hello trace")));
3051
ASSERT_FALSE(content->contains(SW_STRL("hello info")));
3152
ASSERT_TRUE(content->contains(SW_STRL("hello notice")));
3253
ASSERT_TRUE(content->contains(SW_STRL("hello warning")));

0 commit comments

Comments
 (0)