Workaround the server and server_epoll test case

In some cases, the main thread would be interrupted by
SIGCHID, so it needs retry more times or check the status.
This commit is contained in:
zongmin.gu 2021-02-25 10:07:59 +08:00 committed by Zongmin.Gu
parent 37f08da482
commit 4b1b6158fb
3 changed files with 27 additions and 5 deletions

@ -2,7 +2,7 @@
"resource_limits": { "resource_limits": {
"kernel_space_heap_size": "40MB", "kernel_space_heap_size": "40MB",
"kernel_space_stack_size": "1MB", "kernel_space_stack_size": "1MB",
"user_space_size": "400MB", "user_space_size": "420MB",
"max_num_of_threads": 32 "max_num_of_threads": 32
}, },
"process": { "process": {

@ -136,6 +136,12 @@ int server_recvmsg(int client_fd) {
return ret; return ret;
} }
int sigchld = 0;
void proc_exit() {
sigchld = 1;
}
int server_connectionless_recvmsg() { int server_connectionless_recvmsg() {
int ret = 0; int ret = 0;
const int buf_size = 1000; const int buf_size = 1000;
@ -172,6 +178,10 @@ int server_connectionless_recvmsg() {
msg.msg_controllen = 0; msg.msg_controllen = 0;
msg.msg_flags = 0; msg.msg_flags = 0;
if (sigchld != 0) {
return 0;
}
ret = recvmsg(sock, &msg, 0); ret = recvmsg(sock, &msg, 0);
if (ret <= 0) { if (ret <= 0) {
THROW_ERROR("recvmsg failed"); THROW_ERROR("recvmsg failed");
@ -262,6 +272,8 @@ int test_sendmsg_recvmsg_connectionless() {
int ret = 0; int ret = 0;
int child_pid = 0; int child_pid = 0;
signal(SIGCHLD, proc_exit);
char *client_argv[] = {"client", "NULL", "8803", NULL}; char *client_argv[] = {"client", "NULL", "8803", NULL};
ret = posix_spawn(&child_pid, "/bin/client", NULL, NULL, client_argv, NULL); ret = posix_spawn(&child_pid, "/bin/client", NULL, NULL, client_argv, NULL);
if (ret < 0) { if (ret < 0) {

@ -15,6 +15,7 @@
#include "test.h" #include "test.h"
#define MAXEVENTS 64 #define MAXEVENTS 64
#define MAXRETRY_TIMES 3
#define DEFAULT_PROC_NUM 3 #define DEFAULT_PROC_NUM 3
#define DEFAULT_MSG "Hello World!\n" #define DEFAULT_MSG "Hello World!\n"
// The recv buf length should be longer than that of DEFAULT_MSG // The recv buf length should be longer than that of DEFAULT_MSG
@ -89,10 +90,19 @@ int test_ip_socket() {
int count = 0; int count = 0;
while (count < proc_num) { while (count < proc_num) {
struct epoll_event events[MAXEVENTS] = {0}; struct epoll_event events[MAXEVENTS] = {0};
int nfds = epoll_pwait(epfd, events, MAXEVENTS, -1, NULL); int retry_times = 0;
if (nfds == -1) { int nfds = -1;
close_files(2, server_fd, epfd); while (1) {
THROW_ERROR("epoll_wait failed"); nfds = epoll_pwait(epfd, events, MAXEVENTS, -1, NULL);
if (nfds >= 0) {
break;
} else if ( retry_times == MAXRETRY_TIMES ) {
close_files(2, server_fd, epfd);
THROW_ERROR("epoll_wait failed");
}
retry_times++;
} }
for (int i = 0; i < nfds; i++) { for (int i = 0; i < nfds; i++) {