mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-11 13:24:43 -04:00
test/regress: cover event_del() waiting mechanism
Since we have some issues (see refs) for changing waiting order in event_del() I wrote this simple test, so maybe this test can explain something or at least cover what we have before and show it will be broken. P.S. we really need avoid such stuff like lets-test-with-sleep/usleep. Refs: #225 Refs: #226 Refs: #236
This commit is contained in:
parent
8d34302956
commit
5b58b709b2
@ -31,6 +31,10 @@
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifdef EVENT__HAVE_PTHREADS
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include "event2/event-config.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -929,6 +933,67 @@ test_fork(void)
|
||||
cleanup_test();
|
||||
}
|
||||
|
||||
#ifdef EVENT__HAVE_PTHREADS
|
||||
static void* del_wait_thread(void *arg)
|
||||
{
|
||||
struct timeval tv_start, tv_end;
|
||||
|
||||
evutil_gettimeofday(&tv_start, NULL);
|
||||
event_dispatch();
|
||||
evutil_gettimeofday(&tv_end, NULL);
|
||||
|
||||
test_timeval_diff_eq(&tv_start, &tv_end, 300);
|
||||
|
||||
end:
|
||||
;
|
||||
}
|
||||
|
||||
static void
|
||||
del_wait_cb(evutil_socket_t fd, short event, void *arg)
|
||||
{
|
||||
struct timeval delay = { 0, 300*1000 };
|
||||
TT_BLATHER(("Sleeping"));
|
||||
evutil_usleep_(&delay);
|
||||
test_ok = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
test_del_wait(void)
|
||||
{
|
||||
struct event ev;
|
||||
pthread_t thread;
|
||||
|
||||
setup_test("event_del will wait: ");
|
||||
|
||||
event_set(&ev, pair[1], EV_READ, del_wait_cb, &ev);
|
||||
event_add(&ev, NULL);
|
||||
|
||||
pthread_create(&thread, NULL, del_wait_thread, NULL);
|
||||
|
||||
if (write(pair[0], TEST1, strlen(TEST1)+1) < 0) {
|
||||
tt_fail_perror("write");
|
||||
}
|
||||
|
||||
{
|
||||
struct timeval delay = { 0, 30*1000 };
|
||||
evutil_usleep_(&delay);
|
||||
}
|
||||
|
||||
{
|
||||
struct timeval tv_start, tv_end;
|
||||
evutil_gettimeofday(&tv_start, NULL);
|
||||
event_del(&ev);
|
||||
evutil_gettimeofday(&tv_end, NULL);
|
||||
test_timeval_diff_eq(&tv_start, &tv_end, 270);
|
||||
}
|
||||
|
||||
pthread_join(thread, NULL);
|
||||
|
||||
end:
|
||||
;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
signal_cb_sa(int sig)
|
||||
{
|
||||
@ -3301,6 +3366,11 @@ struct testcase_t main_testcases[] = {
|
||||
#ifndef _WIN32
|
||||
LEGACY(fork, TT_ISOLATED),
|
||||
#endif
|
||||
#ifdef EVENT__HAVE_PTHREADS
|
||||
/** TODO: support win32 */
|
||||
LEGACY(del_wait, TT_ISOLATED|TT_NEED_THREADS),
|
||||
#endif
|
||||
|
||||
END_OF_TESTCASES
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user