diff --git a/Makefile.am b/Makefile.am index 61e2f201..4602f82a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -145,6 +145,7 @@ test_run_tests_SOURCES = test/blackhole-server.c \ test/test-list.h \ test/test-loop-handles.c \ test/test-loop-stop.c \ + test/test-loop-time.c \ test/test-multiple-listen.c \ test/test-mutexes.c \ test/test-osx-select.c \ diff --git a/src/unix/core.c b/src/unix/core.c index 79813a05..6bb20573 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -260,6 +260,9 @@ int uv_run(uv_loop_t* loop, uv_run_mode mode) { int r; r = uv__loop_alive(loop); + if (!r) + uv__update_time(loop); + while (r != 0 && loop->stop_flag == 0) { UV_TICK_START(loop, mode); diff --git a/src/win/core.c b/src/win/core.c index 4a9eca26..2eab49f2 100644 --- a/src/win/core.c +++ b/src/win/core.c @@ -273,6 +273,9 @@ int uv_run(uv_loop_t *loop, uv_run_mode mode) { poll = &uv_poll; r = uv__loop_alive(loop); + if (!r) + uv_update_time(loop); + while (r != 0 && loop->stop_flag == 0) { uv_update_time(loop); uv_process_timers(loop); diff --git a/test/test-list.h b/test/test-list.h index 0bbcb349..614ddb33 100644 --- a/test/test-list.h +++ b/test/test-list.h @@ -25,6 +25,7 @@ TEST_DECLARE (close_order) TEST_DECLARE (run_once) TEST_DECLARE (run_nowait) TEST_DECLARE (loop_stop) +TEST_DECLARE (loop_update_time) TEST_DECLARE (barrier_1) TEST_DECLARE (barrier_2) TEST_DECLARE (barrier_3) @@ -251,6 +252,7 @@ TASK_LIST_START TEST_ENTRY (run_once) TEST_ENTRY (run_nowait) TEST_ENTRY (loop_stop) + TEST_ENTRY (loop_update_time) TEST_ENTRY (barrier_1) TEST_ENTRY (barrier_2) TEST_ENTRY (barrier_3) diff --git a/test/test-loop-time.c b/test/test-loop-time.c new file mode 100644 index 00000000..49dc79b2 --- /dev/null +++ b/test/test-loop-time.c @@ -0,0 +1,34 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "uv.h" +#include "task.h" + + +TEST_IMPL(loop_update_time) { + uint64_t start; + + start = uv_now(uv_default_loop()); + while (uv_now(uv_default_loop()) - start < 1000) + ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_NOWAIT)); + + return 0; +} diff --git a/uv.gyp b/uv.gyp index fb37ef58..b9e27305 100644 --- a/uv.gyp +++ b/uv.gyp @@ -324,6 +324,7 @@ 'test/test-list.h', 'test/test-loop-handles.c', 'test/test-loop-stop.c', + 'test/test-loop-time.c', 'test/test-walk-handles.c', 'test/test-watcher-cross-stop.c', 'test/test-multiple-listen.c',