Implement and add test for oio_now()
This commit is contained in:
parent
f12299d6c8
commit
0027dbd976
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user