Skip to content

Commit 922360c

Browse files
committed
Add tests [3] --filter=[core][unit]
1 parent ae5a146 commit 922360c

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

core-tests/src/coroutine/system.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,22 @@ TEST(coroutine_system, getaddrinfo) {
115115
});
116116
}
117117

118+
TEST(coroutine_system, getaddrinfo_fail) {
119+
test::coroutine::run([](void *arg) {
120+
auto ip_list = System::getaddrinfo("w11.baidu.com-not-exists", AF_INET, SOCK_STREAM, 0, "http", -1);
121+
ASSERT_EQ(ip_list.size(), 0);
122+
ASSERT_ERREQ(EAI_NONAME);
123+
});
124+
}
125+
126+
TEST(coroutine_system, getaddrinfo_timeout) {
127+
test::coroutine::run([](void *arg) {
128+
auto ip_list = System::getaddrinfo("w12.baidu.com-not-exists", AF_INET, SOCK_STREAM, 0, "http", 0.005);
129+
ASSERT_EQ(ip_list.size(), 0);
130+
ASSERT_ERREQ(SW_ERROR_CO_TIMEDOUT);
131+
});
132+
}
133+
118134
TEST(coroutine_system, wait_signal) {
119135
test::coroutine::run([](void *arg) {
120136
Coroutine::create([](void *) {
@@ -126,6 +142,22 @@ TEST(coroutine_system, wait_signal) {
126142
});
127143
}
128144

145+
TEST(coroutine_system, wait_signal_invalid_signo) {
146+
test::coroutine::run([](void *arg) {
147+
ASSERT_EQ(System::wait_signal(SW_SIGNO_MAX), SW_ERR);
148+
ASSERT_ERREQ(EINVAL);
149+
});
150+
}
151+
152+
TEST(coroutine_system, wait_signal_fail) {
153+
test::coroutine::run([](void *arg) {
154+
SwooleG.signal_listener_num = 1;
155+
ASSERT_EQ(System::wait_signal(SIGUSR1, 1.0), SW_ERR);
156+
ASSERT_ERREQ(EBUSY);
157+
SwooleG.signal_listener_num = 0;
158+
});
159+
}
160+
129161
static const char *GREETING = "hello world, hello swoole";
130162

131163
TEST(coroutine_system, wait_event_readable) {

core-tests/src/server/server.cpp

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3074,8 +3074,8 @@ TEST(server, send_timeout) {
30743074
ASSERT_EQ(counter[3], 1);
30753075
}
30763076

3077-
TEST(server, max_request) {
3078-
Server serv(Server::MODE_PROCESS);
3077+
static void test_max_request(Server::Mode mode) {
3078+
Server serv(mode);
30793079
serv.worker_num = 2;
30803080
serv.max_request = 128;
30813081

@@ -3092,16 +3092,26 @@ TEST(server, max_request) {
30923092
lock->lock();
30933093
ListenPort *port = serv->get_primary_port();
30943094

3095-
network::SyncClient c(SW_SOCK_TCP);
3096-
c.connect(TEST_HOST, port->port);
3095+
auto client_fn = [&]() {
3096+
network::SyncClient c(SW_SOCK_TCP);
3097+
c.connect(TEST_HOST, port->port);
30973098

3098-
SW_LOOP_N(1024) {
3099-
c.send(packet, strlen(packet));
3100-
usleep(1000);
3099+
SW_LOOP_N(128) {
3100+
if (c.send(packet, strlen(packet)) < 0) {
3101+
break;
3102+
}
3103+
usleep(1000);
3104+
}
3105+
c.close();
3106+
};
3107+
3108+
SW_LOOP_N(8) {
3109+
client_fn();
3110+
usleep(10000);
31013111
}
31023112

31033113
sleep(1);
3104-
c.close();
3114+
31053115
serv->shutdown();
31063116
});
31073117
};
@@ -3121,6 +3131,14 @@ TEST(server, max_request) {
31213131
ASSERT_GE(test::counter_get(0), 8);
31223132
}
31233133

3134+
TEST(server, max_request_1) {
3135+
test_max_request(Server::MODE_PROCESS);
3136+
}
3137+
3138+
TEST(server, max_request_2) {
3139+
test_max_request(Server::MODE_THREAD);
3140+
}
3141+
31243142
TEST(server, watermark) {
31253143
Server serv(Server::MODE_PROCESS);
31263144
serv.worker_num = 2;

0 commit comments

Comments
 (0)