Permalink
Browse files

Unit test for event_remove_timer with EV_PERSIST.

Patch from dcicppin on sourceforge.
  • Loading branch information...
Nick Mathewson
Nick Mathewson committed Feb 13, 2013
1 parent 5623e80 commit 96150dd0c6743cd8082860a8428e117fdbbef6fa
Showing with 22 additions and 7 deletions.
  1. +22 −7 test/regress.c
View
@@ -1430,33 +1430,47 @@ static void send_a_byte_cb(evutil_socket_t fd, short what, void *arg)
(void) fd; (void) what;
write(*sockp, "A", 1);
}
+struct read_not_timeout_param
+{
+ struct event **ev;
+ int events;
+ int count;
+};
static void read_not_timeout_cb(evutil_socket_t fd, short what, void *arg)
{
- int *intp = arg;
+ struct read_not_timeout_param *rntp = arg;
+ char c;
(void) fd; (void) what;
- *intp |= what;
+ read(fd, &c, 1);
+ rntp->events |= what;
+ ++rntp->count;
+ if(2 == rntp->count) event_del(rntp->ev[0]);
}
static void
test_event_remove_timeout(void *ptr)
{
struct basic_test_data *data = ptr;
struct event_base *base = data->base;
- struct event *ev[4];
- int ev0_fired=0, ev1_fired=0;
+ struct event *ev[5];
+ int ev1_fired=0;
struct timeval ms25 = { 0, 25*1000 },
+ ms40 = { 0, 40*1000 },
ms75 = { 0, 75*1000 },
ms125 = { 0, 125*1000 };
+ struct read_not_timeout_param rntp = { ev, 0, 0 };
event_base_assert_ok_(base);
- ev[0] = event_new(base, data->pair[0], EV_READ,
- read_not_timeout_cb, &ev0_fired);
+ ev[0] = event_new(base, data->pair[0], EV_READ|EV_PERSIST,
+ read_not_timeout_cb, &rntp);
ev[1] = evtimer_new(base, incr_arg_cb, &ev1_fired);
ev[2] = evtimer_new(base, remove_timers_cb, ev);
ev[3] = evtimer_new(base, send_a_byte_cb, &data->pair[1]);
+ ev[4] = evtimer_new(base, send_a_byte_cb, &data->pair[1]);
tt_assert(base);
event_add(ev[2], &ms25); /* remove timers */
+ event_add(ev[4], &ms40); /* write to test if timer re-activates */
event_add(ev[0], &ms75); /* read */
event_add(ev[1], &ms75); /* timer */
event_add(ev[3], &ms125); /* timeout. */
@@ -1465,14 +1479,15 @@ test_event_remove_timeout(void *ptr)
event_base_dispatch(base);
tt_int_op(ev1_fired, ==, 0);
- tt_int_op(ev0_fired, ==, EV_READ);
+ tt_int_op(rntp.events, ==, EV_READ);
event_base_assert_ok_(base);
end:
event_free(ev[0]);
event_free(ev[1]);
event_free(ev[2]);
event_free(ev[3]);
+ event_free(ev[4]);
}
static void

0 comments on commit 96150dd

Please sign in to comment.