Skip to content

Commit bd8f7cc

Browse files
committed
Fix tests [5] --filter=[core]
1 parent ca3aae6 commit bd8f7cc

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

core-tests/src/core/base.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,4 +551,7 @@ TEST(base, fork_fail) {
551551

552552
TEST(base, undefined_behavior) {
553553
swoole_init(); // no effect
554+
delete SwooleG.logger;
555+
SwooleG.logger = nullptr; // avoid double free in swoole_shutdown()
556+
ASSERT_EQ(swoole_get_log_level(), SW_LOG_NONE);
554557
}

core-tests/src/coroutine/base.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,3 +326,29 @@ TEST(coroutine_base, bailout) {
326326
});
327327
ASSERT_EQ(WEXITSTATUS(status), 0);
328328
}
329+
330+
TEST(coroutine_base, undefined_behavior) {
331+
int status;
332+
status = test::spawn_exec_and_wait([]() {
333+
test::coroutine::run([](void *) {
334+
swoole_fork(0);
335+
});
336+
});
337+
ASSERT_EQ(1, WEXITSTATUS(status));
338+
339+
status = test::spawn_exec_and_wait([]() {
340+
std::atomic<int> handle_count(0);
341+
AsyncEvent event = {};
342+
event.object = &handle_count;
343+
event.callback = [](AsyncEvent *event) { };
344+
event.handler = [](AsyncEvent *event) { ++(*static_cast<std::atomic<int> *>(event->object)); };
345+
346+
swoole_event_init(0);
347+
auto ret = async::dispatch(&event);
348+
ASSERT_NE(ret, nullptr);
349+
swoole_fork(0);
350+
});
351+
ASSERT_EQ(1, WEXITSTATUS(status));
352+
353+
ASSERT_EQ(0, swoole_fork(SW_FORK_PRECHECK));
354+
}

run-core-tests.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/bin/bash
22
__DIR__=$(cd "$(dirname "$0")" || exit;pwd)
33

4+
export ASAN_OPTIONS=detect_leaks=0
5+
echo 0 > /proc/sys/kernel/randomize_va_space
6+
47
ipcs -q
58

69
cd "${__DIR__}"/core-tests/js || exit 1

src/core/base.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,7 @@ pid_t swoole_fork(int flags) {
341341
}
342342
if (SwooleTG.async_threads) {
343343
swoole_trace("aio_task_num=%lu, reactor=%p", SwooleTG.async_threads->task_num, sw_reactor());
344-
swoole_fatal_error(SW_ERROR_OPERATION_NOT_SUPPORT,
345-
"can not create server after using async file operation");
344+
swoole_fatal_error(SW_ERROR_OPERATION_NOT_SUPPORT, "can not fork after using async-threads");
346345
}
347346
}
348347
if (flags & SW_FORK_PRECHECK) {

0 commit comments

Comments
 (0)