Implement and add test for oio_now()

This commit is contained in:
Ryan Dahl 2011-04-17 23:53:09 -07:00
parent f12299d6c8
commit 0027dbd976
2 changed files with 11 additions and 3 deletions

View File

@ -552,13 +552,12 @@ void oio__timeout(EV_P_ ev_timer* watcher, int revents) {
void oio_update_time() {
assert(0 && "implement me");
ev_now_update(EV_DEFAULT_UC);
}
int64_t oio_now() {
assert(0 && "implement me");
return 0;
return (int64_t)(ev_now(EV_DEFAULT_UC) * 1000);
}

View File

@ -5,16 +5,22 @@
static int expected = 0;
static int timeouts = 0;
static int start_time;
static void timeout_cb(oio_req *req) {
ASSERT(req != NULL);
free(req);
timeouts++;
/* Just call this randomly for the code coverage. */
oio_update_time();
}
static void exit_timeout_cb(oio_req *req) {
int64_t now = oio_now();
ASSERT(req != NULL);
ASSERT(timeouts == expected);
ASSERT(start_time < now);
exit(0);
}
@ -32,6 +38,9 @@ TEST_IMPL(timeout) {
oio_init();
start_time = oio_now();
ASSERT(0 < start_time);
/* Let 10 timers time out in 500 ms total. */
for (i = 0; i < 10; i++) {
req = (oio_req*)malloc(sizeof(*req));