Skip to content

Commit 5a9b01a

Browse files
committed
Fix tests [15] --filter=[core] --verbose
1 parent 5a548f5 commit 5a9b01a

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

core-tests/include/test_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#define TEST_STR2 "I am Rango\n"
4343

4444
#define TEST_LOG_FILE "/tmp/swoole.log"
45+
#define TEST_SOCK_FILE "/tmp/swoole-core-tests.sock"
4546

4647
#define TEST_REQUEST_BAIDU \
4748
"GET / HTTP/1.1\r\n" \

core-tests/src/os/async.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ TEST(async, schedule) {
110110
ASSERT_EQ(callback_count, N);
111111
}
112112

113-
114113
TEST(async, misc) {
115-
int count = 1000;
116114
callback_count = 0;
117115
std::atomic<int> handle_count(0);
118116
AsyncEvent event = {};
@@ -128,7 +126,7 @@ TEST(async, misc) {
128126

129127
sw_async_threads()->notify_one();
130128

131-
AsyncEvent event2 = { };
129+
AsyncEvent event2 = {};
132130
event2.callback = [](AsyncEvent *event) {
133131
ASSERT_EQ(event->retval, -1);
134132
ASSERT_EQ(event->error, SW_ERROR_AIO_BAD_REQUEST);

core-tests/src/os/process_pool.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ static void test_func(ProcessPool &pool) {
2121
data.info.len = size;
2222
memcpy(data.data, rmem.value(), size);
2323

24+
DEBUG() << "dispatch: " << size << " bytes\n";
25+
2426
int worker_id = -1;
2527
ASSERT_EQ(pool.dispatch_sync(&data, &worker_id), SW_OK);
2628

@@ -48,6 +50,8 @@ static void test_func_message_protocol(ProcessPool &pool) {
4850
pool->running = false;
4951
String *_data = (String *) pool->ptr;
5052
usleep(10000);
53+
54+
DEBUG() << "received: " << rdata->info.len << " bytes\n";
5155
EXPECT_MEMEQ(_data->str, rdata->data, rdata->info.len);
5256
};
5357
test_func(pool);
@@ -60,6 +64,8 @@ static void test_func_stream_protocol(ProcessPool &pool) {
6064
String *_data = (String *) pool->ptr;
6165
EventData *msg = (EventData *) rdata->data;
6266
usleep(10000);
67+
68+
DEBUG() << "received: " << rdata->info.len << " bytes\n";
6369
EXPECT_MEMEQ(_data->str, msg->data, msg->len());
6470
};
6571
test_func(pool);
@@ -93,6 +99,10 @@ TEST(process_pool, unix_sock) {
9399
ProcessPool pool{};
94100
signal(SIGPIPE, SIG_IGN);
95101
ASSERT_EQ(pool.create(1, 0, SW_IPC_UNIXSOCK), SW_OK);
102+
ASSERT_EQ(pool.listen(TEST_HOST, TEST_PORT, 128), SW_ERR);
103+
ASSERT_ERREQ(SW_ERROR_OPERATION_NOT_SUPPORT);
104+
ASSERT_EQ(pool.listen(TEST_SOCK_FILE, 128), SW_ERR);
105+
ASSERT_ERREQ(SW_ERROR_OPERATION_NOT_SUPPORT);
96106

97107
test_func_task_protocol(pool);
98108
}
@@ -144,6 +154,13 @@ TEST(process_pool, stream_protocol) {
144154
test_func_stream_protocol(pool);
145155
}
146156

157+
TEST(process_pool, stream_protocol_with_msgq) {
158+
ProcessPool pool{};
159+
ASSERT_EQ(pool.create(1, 0x9501, SW_IPC_MSGQUEUE), SW_OK);
160+
161+
test_func_stream_protocol(pool);
162+
}
163+
147164
constexpr int magic_number = 99900011;
148165
static ProcessPool *current_pool = nullptr;
149166
static Worker *current_worker = nullptr;

src/core/misc.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,3 @@ uint64_t swoole_hash_austin(const char *key, size_t keylen) {
223223

224224
return h;
225225
}
226-

src/os/process_pool.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ int ProcessPool::listen(const char *socket_file, int blacklog) {
171171

172172
int ProcessPool::listen(const char *host, int port, int blacklog) {
173173
if (ipc_mode != SW_IPC_SOCKET) {
174-
swoole_warning("ipc_mode is not SW_IPC_SOCKET");
174+
swoole_error_log(SW_LOG_WARNING, SW_ERROR_OPERATION_NOT_SUPPORT, "not support, ipc_mode must be SW_IPC_SOCKET");
175175
return SW_ERR;
176176
}
177177
stream_info_->socket_file = sw_strdup(host);
@@ -682,6 +682,8 @@ int ProcessPool::run_with_stream_protocol(ProcessPool *pool, Worker *worker) {
682682
swoole_sys_warning("[Worker#%d] msgrcv(%d) failed", worker->id, pool->queue->get_id());
683683
break;
684684
}
685+
swoole_trace_log(SW_TRACE_WORKER, "pop from MsgQ#%d %lu bytes", pool->queue->get_id(), (ulong_t) n);
686+
msg.info.len = n - sizeof(msg.info);
685687
msg.data = outbuf->mdata;
686688
outbuf->mtype = 0;
687689
} else if (pool->use_socket) {
@@ -1092,6 +1094,8 @@ ssize_t Worker::send_pipe_message(const void *buf, size_t n, int flags) {
10921094
msg.mtype = id + 1;
10931095
memcpy(&msg.buf, buf, n);
10941096

1097+
swoole_trace_log(SW_TRACE_WORKER, "push to MsgQ#%d %lu bytes", pool->queue->get_id(), (ulong_t) n);
1098+
10951099
return pool->queue->push((QueueNode *) &msg, n) ? n : -1;
10961100
}
10971101

0 commit comments

Comments
 (0)