1 1.1 christos /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 1.1 christos * 3 1.1 christos * Permission is hereby granted, free of charge, to any person obtaining a copy 4 1.1 christos * of this software and associated documentation files (the "Software"), to 5 1.1 christos * deal in the Software without restriction, including without limitation the 6 1.1 christos * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 1.1 christos * sell copies of the Software, and to permit persons to whom the Software is 8 1.1 christos * furnished to do so, subject to the following conditions: 9 1.1 christos * 10 1.1 christos * The above copyright notice and this permission notice shall be included in 11 1.1 christos * all copies or substantial portions of the Software. 12 1.1 christos * 13 1.1 christos * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 1.1 christos * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 1.1 christos * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 1.1 christos * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 1.1 christos * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 1.1 christos * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 1.1 christos * IN THE SOFTWARE. 20 1.1 christos */ 21 1.1 christos 22 1.1 christos #include "uv.h" 23 1.1 christos #include "task.h" 24 1.1 christos 25 1.1 christos 26 1.1 christos static int once_cb_called = 0; 27 1.1 christos static int once_close_cb_called = 0; 28 1.1.1.2 christos static int twice_cb_called = 0; 29 1.1.1.2 christos static int twice_close_cb_called = 0; 30 1.1 christos static int repeat_cb_called = 0; 31 1.1 christos static int repeat_close_cb_called = 0; 32 1.1 christos static int order_cb_called = 0; 33 1.1.1.3 christos static int timer_check_double_call_called = 0; 34 1.1.1.3 christos static int zero_timeout_cb_calls = 0; 35 1.1 christos static uint64_t start_time; 36 1.1 christos static uv_timer_t tiny_timer; 37 1.1 christos static uv_timer_t huge_timer1; 38 1.1 christos static uv_timer_t huge_timer2; 39 1.1 christos 40 1.1 christos 41 1.1 christos static void once_close_cb(uv_handle_t* handle) { 42 1.1 christos printf("ONCE_CLOSE_CB\n"); 43 1.1 christos 44 1.1.1.2 christos ASSERT_NOT_NULL(handle); 45 1.1.1.3 christos ASSERT_OK(uv_is_active(handle)); 46 1.1 christos 47 1.1 christos once_close_cb_called++; 48 1.1 christos } 49 1.1 christos 50 1.1 christos 51 1.1 christos static void once_cb(uv_timer_t* handle) { 52 1.1 christos printf("ONCE_CB %d\n", once_cb_called); 53 1.1 christos 54 1.1.1.2 christos ASSERT_NOT_NULL(handle); 55 1.1.1.3 christos ASSERT_OK(uv_is_active((uv_handle_t*) handle)); 56 1.1 christos 57 1.1 christos once_cb_called++; 58 1.1 christos 59 1.1 christos uv_close((uv_handle_t*)handle, once_close_cb); 60 1.1 christos 61 1.1 christos /* Just call this randomly for the code coverage. */ 62 1.1 christos uv_update_time(uv_default_loop()); 63 1.1 christos } 64 1.1 christos 65 1.1.1.2 christos static void twice_close_cb(uv_handle_t* handle) { 66 1.1.1.2 christos printf("TWICE_CLOSE_CB\n"); 67 1.1.1.2 christos 68 1.1.1.2 christos ASSERT_NOT_NULL(handle); 69 1.1.1.3 christos ASSERT_OK(uv_is_active(handle)); 70 1.1.1.2 christos 71 1.1.1.2 christos twice_close_cb_called++; 72 1.1.1.2 christos } 73 1.1.1.2 christos 74 1.1.1.2 christos static void twice_cb(uv_timer_t* handle) { 75 1.1.1.2 christos printf("TWICE_CB %d\n", twice_cb_called); 76 1.1.1.2 christos 77 1.1.1.2 christos ASSERT_NOT_NULL(handle); 78 1.1.1.3 christos ASSERT_OK(uv_is_active((uv_handle_t*) handle)); 79 1.1.1.2 christos 80 1.1.1.2 christos twice_cb_called++; 81 1.1.1.2 christos 82 1.1.1.2 christos uv_close((uv_handle_t*)handle, twice_close_cb); 83 1.1.1.2 christos } 84 1.1.1.2 christos 85 1.1.1.2 christos 86 1.1 christos 87 1.1 christos static void repeat_close_cb(uv_handle_t* handle) { 88 1.1 christos printf("REPEAT_CLOSE_CB\n"); 89 1.1 christos 90 1.1.1.2 christos ASSERT_NOT_NULL(handle); 91 1.1 christos 92 1.1 christos repeat_close_cb_called++; 93 1.1 christos } 94 1.1 christos 95 1.1 christos 96 1.1 christos static void repeat_cb(uv_timer_t* handle) { 97 1.1 christos printf("REPEAT_CB\n"); 98 1.1 christos 99 1.1.1.2 christos ASSERT_NOT_NULL(handle); 100 1.1.1.3 christos ASSERT_EQ(1, uv_is_active((uv_handle_t*) handle)); 101 1.1 christos 102 1.1 christos repeat_cb_called++; 103 1.1 christos 104 1.1 christos if (repeat_cb_called == 5) { 105 1.1 christos uv_close((uv_handle_t*)handle, repeat_close_cb); 106 1.1 christos } 107 1.1 christos } 108 1.1 christos 109 1.1 christos 110 1.1 christos static void never_cb(uv_timer_t* handle) { 111 1.1 christos FATAL("never_cb should never be called"); 112 1.1 christos } 113 1.1 christos 114 1.1 christos 115 1.1 christos TEST_IMPL(timer) { 116 1.1 christos uv_timer_t once_timers[10]; 117 1.1 christos uv_timer_t *once; 118 1.1 christos uv_timer_t repeat, never; 119 1.1 christos unsigned int i; 120 1.1 christos int r; 121 1.1 christos 122 1.1 christos start_time = uv_now(uv_default_loop()); 123 1.1.1.3 christos ASSERT_LT(0, start_time); 124 1.1 christos 125 1.1 christos /* Let 10 timers time out in 500 ms total. */ 126 1.1 christos for (i = 0; i < ARRAY_SIZE(once_timers); i++) { 127 1.1 christos once = once_timers + i; 128 1.1 christos r = uv_timer_init(uv_default_loop(), once); 129 1.1.1.3 christos ASSERT_OK(r); 130 1.1 christos r = uv_timer_start(once, once_cb, i * 50, 0); 131 1.1.1.3 christos ASSERT_OK(r); 132 1.1 christos } 133 1.1 christos 134 1.1 christos /* The 11th timer is a repeating timer that runs 4 times */ 135 1.1 christos r = uv_timer_init(uv_default_loop(), &repeat); 136 1.1.1.3 christos ASSERT_OK(r); 137 1.1 christos r = uv_timer_start(&repeat, repeat_cb, 100, 100); 138 1.1.1.3 christos ASSERT_OK(r); 139 1.1 christos 140 1.1 christos /* The 12th timer should not do anything. */ 141 1.1 christos r = uv_timer_init(uv_default_loop(), &never); 142 1.1.1.3 christos ASSERT_OK(r); 143 1.1 christos r = uv_timer_start(&never, never_cb, 100, 100); 144 1.1.1.3 christos ASSERT_OK(r); 145 1.1 christos r = uv_timer_stop(&never); 146 1.1.1.3 christos ASSERT_OK(r); 147 1.1 christos uv_unref((uv_handle_t*)&never); 148 1.1 christos 149 1.1 christos uv_run(uv_default_loop(), UV_RUN_DEFAULT); 150 1.1 christos 151 1.1.1.3 christos ASSERT_EQ(10, once_cb_called); 152 1.1.1.3 christos ASSERT_EQ(10, once_close_cb_called); 153 1.1 christos printf("repeat_cb_called %d\n", repeat_cb_called); 154 1.1.1.3 christos ASSERT_EQ(5, repeat_cb_called); 155 1.1.1.3 christos ASSERT_EQ(1, repeat_close_cb_called); 156 1.1 christos 157 1.1.1.3 christos ASSERT_LE(500, uv_now(uv_default_loop()) - start_time); 158 1.1 christos 159 1.1.1.3 christos MAKE_VALGRIND_HAPPY(uv_default_loop()); 160 1.1 christos return 0; 161 1.1 christos } 162 1.1 christos 163 1.1 christos 164 1.1 christos TEST_IMPL(timer_start_twice) { 165 1.1 christos uv_timer_t once; 166 1.1 christos int r; 167 1.1 christos 168 1.1 christos r = uv_timer_init(uv_default_loop(), &once); 169 1.1.1.3 christos ASSERT_OK(r); 170 1.1 christos r = uv_timer_start(&once, never_cb, 86400 * 1000, 0); 171 1.1.1.3 christos ASSERT_OK(r); 172 1.1.1.2 christos r = uv_timer_start(&once, twice_cb, 10, 0); 173 1.1.1.3 christos ASSERT_OK(r); 174 1.1 christos r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); 175 1.1.1.3 christos ASSERT_OK(r); 176 1.1 christos 177 1.1.1.3 christos ASSERT_EQ(1, twice_cb_called); 178 1.1 christos 179 1.1.1.3 christos MAKE_VALGRIND_HAPPY(uv_default_loop()); 180 1.1 christos return 0; 181 1.1 christos } 182 1.1 christos 183 1.1 christos 184 1.1 christos TEST_IMPL(timer_init) { 185 1.1 christos uv_timer_t handle; 186 1.1 christos 187 1.1.1.3 christos ASSERT_OK(uv_timer_init(uv_default_loop(), &handle)); 188 1.1.1.3 christos ASSERT_OK(uv_timer_get_repeat(&handle)); 189 1.1.1.2 christos ASSERT_UINT64_LE(0, uv_timer_get_due_in(&handle)); 190 1.1.1.3 christos ASSERT_OK(uv_is_active((uv_handle_t*) &handle)); 191 1.1 christos 192 1.1.1.3 christos MAKE_VALGRIND_HAPPY(uv_default_loop()); 193 1.1 christos return 0; 194 1.1 christos } 195 1.1 christos 196 1.1 christos 197 1.1 christos static void order_cb_a(uv_timer_t *handle) { 198 1.1.1.3 christos ASSERT_EQ(order_cb_called++, *(int*)handle->data); 199 1.1 christos } 200 1.1 christos 201 1.1 christos 202 1.1 christos static void order_cb_b(uv_timer_t *handle) { 203 1.1.1.3 christos ASSERT_EQ(order_cb_called++, *(int*)handle->data); 204 1.1 christos } 205 1.1 christos 206 1.1 christos 207 1.1 christos TEST_IMPL(timer_order) { 208 1.1 christos int first; 209 1.1 christos int second; 210 1.1 christos uv_timer_t handle_a; 211 1.1 christos uv_timer_t handle_b; 212 1.1 christos 213 1.1 christos first = 0; 214 1.1 christos second = 1; 215 1.1.1.3 christos ASSERT_OK(uv_timer_init(uv_default_loop(), &handle_a)); 216 1.1.1.3 christos ASSERT_OK(uv_timer_init(uv_default_loop(), &handle_b)); 217 1.1 christos 218 1.1 christos /* Test for starting handle_a then handle_b */ 219 1.1 christos handle_a.data = &first; 220 1.1.1.3 christos ASSERT_OK(uv_timer_start(&handle_a, order_cb_a, 0, 0)); 221 1.1 christos handle_b.data = &second; 222 1.1.1.3 christos ASSERT_OK(uv_timer_start(&handle_b, order_cb_b, 0, 0)); 223 1.1.1.3 christos ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT)); 224 1.1 christos 225 1.1.1.3 christos ASSERT_EQ(2, order_cb_called); 226 1.1 christos 227 1.1.1.3 christos ASSERT_OK(uv_timer_stop(&handle_a)); 228 1.1.1.3 christos ASSERT_OK(uv_timer_stop(&handle_b)); 229 1.1 christos 230 1.1 christos /* Test for starting handle_b then handle_a */ 231 1.1 christos order_cb_called = 0; 232 1.1 christos handle_b.data = &first; 233 1.1.1.3 christos ASSERT_OK(uv_timer_start(&handle_b, order_cb_b, 0, 0)); 234 1.1 christos 235 1.1 christos handle_a.data = &second; 236 1.1.1.3 christos ASSERT_OK(uv_timer_start(&handle_a, order_cb_a, 0, 0)); 237 1.1.1.3 christos ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT)); 238 1.1 christos 239 1.1.1.3 christos ASSERT_EQ(2, order_cb_called); 240 1.1 christos 241 1.1.1.3 christos MAKE_VALGRIND_HAPPY(uv_default_loop()); 242 1.1.1.3 christos return 0; 243 1.1.1.3 christos } 244 1.1.1.3 christos 245 1.1.1.3 christos 246 1.1.1.3 christos static void zero_timeout_cb(uv_timer_t* handle) { 247 1.1.1.3 christos ASSERT_OK(uv_timer_start(handle, zero_timeout_cb, 0, 0)); 248 1.1.1.3 christos uv_stop(handle->loop); 249 1.1.1.3 christos zero_timeout_cb_calls++; 250 1.1.1.3 christos } 251 1.1.1.3 christos 252 1.1.1.3 christos 253 1.1.1.3 christos TEST_IMPL(timer_zero_timeout) { 254 1.1.1.3 christos uv_timer_t timer; 255 1.1.1.3 christos uv_loop_t* loop; 256 1.1.1.3 christos 257 1.1.1.3 christos loop = uv_default_loop(); 258 1.1.1.3 christos ASSERT_OK(uv_timer_init(loop, &timer)); 259 1.1.1.3 christos ASSERT_OK(uv_timer_start(&timer, zero_timeout_cb, 0, 0)); 260 1.1.1.3 christos ASSERT_EQ(1, uv_run(loop, UV_RUN_DEFAULT)); /* because of uv_stop() */ 261 1.1.1.3 christos ASSERT_EQ(1, zero_timeout_cb_calls); 262 1.1.1.3 christos uv_close((uv_handle_t*) &timer, NULL); 263 1.1.1.3 christos ASSERT_OK(uv_run(loop, UV_RUN_DEFAULT)); 264 1.1.1.3 christos ASSERT_EQ(1, zero_timeout_cb_calls); 265 1.1.1.3 christos 266 1.1.1.3 christos MAKE_VALGRIND_HAPPY(loop); 267 1.1 christos return 0; 268 1.1 christos } 269 1.1 christos 270 1.1 christos 271 1.1 christos static void tiny_timer_cb(uv_timer_t* handle) { 272 1.1.1.3 christos ASSERT_PTR_EQ(handle, &tiny_timer); 273 1.1 christos uv_close((uv_handle_t*) &tiny_timer, NULL); 274 1.1 christos uv_close((uv_handle_t*) &huge_timer1, NULL); 275 1.1 christos uv_close((uv_handle_t*) &huge_timer2, NULL); 276 1.1 christos } 277 1.1 christos 278 1.1 christos 279 1.1 christos TEST_IMPL(timer_huge_timeout) { 280 1.1.1.3 christos ASSERT_OK(uv_timer_init(uv_default_loop(), &tiny_timer)); 281 1.1.1.3 christos ASSERT_OK(uv_timer_init(uv_default_loop(), &huge_timer1)); 282 1.1.1.3 christos ASSERT_OK(uv_timer_init(uv_default_loop(), &huge_timer2)); 283 1.1.1.3 christos ASSERT_OK(uv_timer_start(&tiny_timer, tiny_timer_cb, 1, 0)); 284 1.1.1.3 christos ASSERT_OK(uv_timer_start(&huge_timer1, 285 1.1.1.3 christos tiny_timer_cb, 286 1.1.1.3 christos 0xffffffffffffLL, 287 1.1.1.3 christos 0)); 288 1.1.1.3 christos ASSERT_OK(uv_timer_start(&huge_timer2, tiny_timer_cb, (uint64_t) -1, 0)); 289 1.1.1.2 christos ASSERT_UINT64_EQ(1, uv_timer_get_due_in(&tiny_timer)); 290 1.1.1.2 christos ASSERT_UINT64_EQ(281474976710655, uv_timer_get_due_in(&huge_timer1)); 291 1.1.1.2 christos ASSERT_UINT64_LE(0, uv_timer_get_due_in(&huge_timer2)); 292 1.1.1.3 christos ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT)); 293 1.1.1.3 christos MAKE_VALGRIND_HAPPY(uv_default_loop()); 294 1.1 christos return 0; 295 1.1 christos } 296 1.1 christos 297 1.1 christos 298 1.1 christos static void huge_repeat_cb(uv_timer_t* handle) { 299 1.1 christos static int ncalls; 300 1.1 christos 301 1.1 christos if (ncalls == 0) 302 1.1.1.3 christos ASSERT_PTR_EQ(handle, &huge_timer1); 303 1.1 christos else 304 1.1.1.3 christos ASSERT_PTR_EQ(handle, &tiny_timer); 305 1.1 christos 306 1.1 christos if (++ncalls == 10) { 307 1.1 christos uv_close((uv_handle_t*) &tiny_timer, NULL); 308 1.1 christos uv_close((uv_handle_t*) &huge_timer1, NULL); 309 1.1 christos } 310 1.1 christos } 311 1.1 christos 312 1.1 christos 313 1.1 christos TEST_IMPL(timer_huge_repeat) { 314 1.1.1.3 christos ASSERT_OK(uv_timer_init(uv_default_loop(), &tiny_timer)); 315 1.1.1.3 christos ASSERT_OK(uv_timer_init(uv_default_loop(), &huge_timer1)); 316 1.1.1.3 christos ASSERT_OK(uv_timer_start(&tiny_timer, huge_repeat_cb, 2, 2)); 317 1.1.1.3 christos ASSERT_OK(uv_timer_start(&huge_timer1, huge_repeat_cb, 1, (uint64_t) -1)); 318 1.1.1.3 christos ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT)); 319 1.1.1.3 christos MAKE_VALGRIND_HAPPY(uv_default_loop()); 320 1.1 christos return 0; 321 1.1 christos } 322 1.1 christos 323 1.1 christos 324 1.1 christos static unsigned int timer_run_once_timer_cb_called; 325 1.1 christos 326 1.1 christos 327 1.1 christos static void timer_run_once_timer_cb(uv_timer_t* handle) { 328 1.1 christos timer_run_once_timer_cb_called++; 329 1.1 christos } 330 1.1 christos 331 1.1 christos 332 1.1 christos TEST_IMPL(timer_run_once) { 333 1.1 christos uv_timer_t timer_handle; 334 1.1 christos 335 1.1.1.3 christos ASSERT_OK(uv_timer_init(uv_default_loop(), &timer_handle)); 336 1.1.1.3 christos ASSERT_OK(uv_timer_start(&timer_handle, timer_run_once_timer_cb, 0, 0)); 337 1.1.1.3 christos ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_ONCE)); 338 1.1.1.3 christos ASSERT_EQ(1, timer_run_once_timer_cb_called); 339 1.1.1.3 christos 340 1.1.1.3 christos ASSERT_OK(uv_timer_start(&timer_handle, timer_run_once_timer_cb, 1, 0)); 341 1.1.1.3 christos ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_ONCE)); 342 1.1.1.3 christos ASSERT_EQ(2, timer_run_once_timer_cb_called); 343 1.1 christos 344 1.1 christos uv_close((uv_handle_t*) &timer_handle, NULL); 345 1.1.1.3 christos ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_ONCE)); 346 1.1 christos 347 1.1.1.3 christos MAKE_VALGRIND_HAPPY(uv_default_loop()); 348 1.1 christos return 0; 349 1.1 christos } 350 1.1 christos 351 1.1 christos 352 1.1 christos TEST_IMPL(timer_is_closing) { 353 1.1 christos uv_timer_t handle; 354 1.1 christos 355 1.1.1.3 christos ASSERT_OK(uv_timer_init(uv_default_loop(), &handle)); 356 1.1 christos uv_close((uv_handle_t *)&handle, NULL); 357 1.1 christos 358 1.1.1.3 christos ASSERT_EQ(UV_EINVAL, uv_timer_start(&handle, never_cb, 100, 100)); 359 1.1 christos 360 1.1.1.3 christos MAKE_VALGRIND_HAPPY(uv_default_loop()); 361 1.1 christos return 0; 362 1.1 christos } 363 1.1 christos 364 1.1 christos 365 1.1 christos TEST_IMPL(timer_null_callback) { 366 1.1 christos uv_timer_t handle; 367 1.1 christos 368 1.1.1.3 christos ASSERT_OK(uv_timer_init(uv_default_loop(), &handle)); 369 1.1.1.3 christos ASSERT_EQ(UV_EINVAL, uv_timer_start(&handle, NULL, 100, 100)); 370 1.1 christos 371 1.1.1.3 christos MAKE_VALGRIND_HAPPY(uv_default_loop()); 372 1.1 christos return 0; 373 1.1 christos } 374 1.1 christos 375 1.1 christos 376 1.1 christos static uint64_t timer_early_check_expected_time; 377 1.1 christos 378 1.1 christos 379 1.1 christos static void timer_early_check_cb(uv_timer_t* handle) { 380 1.1 christos uint64_t hrtime = uv_hrtime() / 1000000; 381 1.1.1.3 christos ASSERT_GE(hrtime, timer_early_check_expected_time); 382 1.1 christos } 383 1.1 christos 384 1.1 christos 385 1.1 christos TEST_IMPL(timer_early_check) { 386 1.1 christos uv_timer_t timer_handle; 387 1.1 christos const uint64_t timeout_ms = 10; 388 1.1 christos 389 1.1 christos timer_early_check_expected_time = uv_now(uv_default_loop()) + timeout_ms; 390 1.1 christos 391 1.1.1.3 christos ASSERT_OK(uv_timer_init(uv_default_loop(), &timer_handle)); 392 1.1.1.3 christos ASSERT_OK(uv_timer_start(&timer_handle, 393 1.1.1.3 christos timer_early_check_cb, 394 1.1.1.3 christos timeout_ms, 395 1.1.1.3 christos 0)); 396 1.1.1.3 christos ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT)); 397 1.1 christos 398 1.1 christos uv_close((uv_handle_t*) &timer_handle, NULL); 399 1.1.1.3 christos ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT)); 400 1.1.1.3 christos 401 1.1.1.3 christos MAKE_VALGRIND_HAPPY(uv_default_loop()); 402 1.1.1.3 christos return 0; 403 1.1.1.3 christos } 404 1.1.1.3 christos 405 1.1.1.3 christos static void timer_check_double_call(uv_timer_t* handle) { 406 1.1.1.3 christos timer_check_double_call_called++; 407 1.1.1.3 christos } 408 1.1.1.3 christos 409 1.1.1.3 christos TEST_IMPL(timer_no_double_call_once) { 410 1.1.1.3 christos uv_timer_t timer_handle; 411 1.1.1.3 christos const uint64_t timeout_ms = 10; 412 1.1.1.3 christos 413 1.1.1.3 christos ASSERT_OK(uv_timer_init(uv_default_loop(), &timer_handle)); 414 1.1.1.3 christos ASSERT_OK(uv_timer_start(&timer_handle, 415 1.1.1.3 christos timer_check_double_call, 416 1.1.1.3 christos timeout_ms, 417 1.1.1.3 christos timeout_ms)); 418 1.1.1.3 christos uv_sleep(timeout_ms * 2); 419 1.1.1.3 christos ASSERT_EQ(1, uv_run(uv_default_loop(), UV_RUN_ONCE)); 420 1.1.1.3 christos ASSERT_EQ(1, timer_check_double_call_called); 421 1.1.1.3 christos 422 1.1.1.3 christos MAKE_VALGRIND_HAPPY(uv_default_loop()); 423 1.1.1.3 christos return 0; 424 1.1.1.3 christos } 425 1.1.1.3 christos 426 1.1.1.3 christos TEST_IMPL(timer_no_double_call_nowait) { 427 1.1.1.3 christos uv_timer_t timer_handle; 428 1.1.1.3 christos const uint64_t timeout_ms = 10; 429 1.1.1.3 christos 430 1.1.1.3 christos ASSERT_OK(uv_timer_init(uv_default_loop(), &timer_handle)); 431 1.1.1.3 christos ASSERT_OK(uv_timer_start(&timer_handle, 432 1.1.1.3 christos timer_check_double_call, 433 1.1.1.3 christos timeout_ms, 434 1.1.1.3 christos timeout_ms)); 435 1.1.1.3 christos uv_sleep(timeout_ms * 2); 436 1.1.1.3 christos ASSERT_EQ(1, uv_run(uv_default_loop(), UV_RUN_NOWAIT)); 437 1.1.1.3 christos ASSERT_EQ(1, timer_check_double_call_called); 438 1.1.1.3 christos 439 1.1.1.3 christos MAKE_VALGRIND_HAPPY(uv_default_loop()); 440 1.1.1.3 christos return 0; 441 1.1.1.3 christos } 442 1.1.1.3 christos 443 1.1.1.3 christos TEST_IMPL(timer_no_run_on_unref) { 444 1.1.1.3 christos uv_timer_t timer_handle; 445 1.1.1.3 christos 446 1.1.1.3 christos ASSERT_OK(uv_timer_init(uv_default_loop(), &timer_handle)); 447 1.1.1.3 christos ASSERT_OK(uv_timer_start(&timer_handle, (uv_timer_cb) abort, 0, 0)); 448 1.1.1.3 christos uv_unref((uv_handle_t*) &timer_handle); 449 1.1.1.3 christos ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT)); 450 1.1 christos 451 1.1.1.3 christos MAKE_VALGRIND_HAPPY(uv_default_loop()); 452 1.1 christos return 0; 453 1.1 christos } 454