From 0027dbd976f5d1ddd3f7a491abffff8354798e56 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sun, 17 Apr 2011 23:53:09 -0700 Subject: [PATCH] Implement and add test for oio_now() --- oio-unix.c | 5 ++--- test/test-timeout.c | 9 +++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/oio-unix.c b/oio-unix.c index b6d6d6e8..5d08abe3 100644 --- a/oio-unix.c +++ b/oio-unix.c @@ -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); } diff --git a/test/test-timeout.c b/test/test-timeout.c index aad2c056..0da89a28 100644 --- a/test/test-timeout.c +++ b/test/test-timeout.c @@ -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));