Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 97 lines (72 sloc) 2.733 kB
f0c20aa @piscisaureus Test: active idle watcher should not block other events
piscisaureus authored
1 /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to
5 * deal in the Software without restriction, including without limitation the
6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 * sell copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 * IN THE SOFTWARE.
20 */
21
22 #include "uv.h"
23 #include "task.h"
24
25
26 static uv_idle_t idle_handle;
b5cd78e @piscisaureus test: reflect new idle semantics in test
piscisaureus authored
27 static uv_check_t check_handle;
28 static uv_timer_t timer_handle;
f0c20aa @piscisaureus Test: active idle watcher should not block other events
piscisaureus authored
29
30 static int idle_cb_called = 0;
b5cd78e @piscisaureus test: reflect new idle semantics in test
piscisaureus authored
31 static int check_cb_called = 0;
f0c20aa @piscisaureus Test: active idle watcher should not block other events
piscisaureus authored
32 static int timer_cb_called = 0;
33 static int close_cb_called = 0;
34
35
36 static void close_cb(uv_handle_t* handle) {
37 close_cb_called++;
38 }
39
40
db2a907 @saghul unix, windows: removed unused status parameter
saghul authored
41 static void timer_cb(uv_timer_t* handle) {
f0c20aa @piscisaureus Test: active idle watcher should not block other events
piscisaureus authored
42 ASSERT(handle == &timer_handle);
43
b931c93 @ry uv_close returns void
ry authored
44 uv_close((uv_handle_t*) &idle_handle, close_cb);
b5cd78e @piscisaureus test: reflect new idle semantics in test
piscisaureus authored
45 uv_close((uv_handle_t*) &check_handle, close_cb);
5f12c30 @piscisaureus Correct idle_starvation test
piscisaureus authored
46 uv_close((uv_handle_t*) &timer_handle, close_cb);
f0c20aa @piscisaureus Test: active idle watcher should not block other events
piscisaureus authored
47
48 timer_cb_called++;
5f12c30 @piscisaureus Correct idle_starvation test
piscisaureus authored
49 LOGF("timer_cb %d\n", timer_cb_called);
f0c20aa @piscisaureus Test: active idle watcher should not block other events
piscisaureus authored
50 }
51
52
db2a907 @saghul unix, windows: removed unused status parameter
saghul authored
53 static void idle_cb(uv_idle_t* handle) {
f0c20aa @piscisaureus Test: active idle watcher should not block other events
piscisaureus authored
54 ASSERT(handle == &idle_handle);
55
56 idle_cb_called++;
5f12c30 @piscisaureus Correct idle_starvation test
piscisaureus authored
57 LOGF("idle_cb %d\n", idle_cb_called);
f0c20aa @piscisaureus Test: active idle watcher should not block other events
piscisaureus authored
58 }
59
60
db2a907 @saghul unix, windows: removed unused status parameter
saghul authored
61 static void check_cb(uv_check_t* handle) {
b5cd78e @piscisaureus test: reflect new idle semantics in test
piscisaureus authored
62 ASSERT(handle == &check_handle);
63
64 check_cb_called++;
65 LOGF("check_cb %d\n", check_cb_called);
66 }
67
68
f0c20aa @piscisaureus Test: active idle watcher should not block other events
piscisaureus authored
69 TEST_IMPL(idle_starvation) {
70 int r;
71
56dcaf9 @ry unix: multiplicity
ry authored
72 r = uv_idle_init(uv_default_loop(), &idle_handle);
f0c20aa @piscisaureus Test: active idle watcher should not block other events
piscisaureus authored
73 ASSERT(r == 0);
74 r = uv_idle_start(&idle_handle, idle_cb);
75 ASSERT(r == 0);
76
b5cd78e @piscisaureus test: reflect new idle semantics in test
piscisaureus authored
77 r = uv_check_init(uv_default_loop(), &check_handle);
78 ASSERT(r == 0);
79 r = uv_check_start(&check_handle, check_cb);
80 ASSERT(r == 0);
81
56dcaf9 @ry unix: multiplicity
ry authored
82 r = uv_timer_init(uv_default_loop(), &timer_handle);
f0c20aa @piscisaureus Test: active idle watcher should not block other events
piscisaureus authored
83 ASSERT(r == 0);
5f12c30 @piscisaureus Correct idle_starvation test
piscisaureus authored
84 r = uv_timer_start(&timer_handle, timer_cb, 50, 0);
f0c20aa @piscisaureus Test: active idle watcher should not block other events
piscisaureus authored
85 ASSERT(r == 0);
86
4ba03dd @bnoordhuis unix, windows: rename uv_run2 to uv_run
bnoordhuis authored
87 r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
f0c20aa @piscisaureus Test: active idle watcher should not block other events
piscisaureus authored
88 ASSERT(r == 0);
89
5f12c30 @piscisaureus Correct idle_starvation test
piscisaureus authored
90 ASSERT(idle_cb_called > 0);
f0c20aa @piscisaureus Test: active idle watcher should not block other events
piscisaureus authored
91 ASSERT(timer_cb_called == 1);
b5cd78e @piscisaureus test: reflect new idle semantics in test
piscisaureus authored
92 ASSERT(close_cb_called == 3);
f0c20aa @piscisaureus Test: active idle watcher should not block other events
piscisaureus authored
93
47eb034 @piscisaureus test: move loop cleanup code to the individual tests
piscisaureus authored
94 MAKE_VALGRIND_HAPPY();
f0c20aa @piscisaureus Test: active idle watcher should not block other events
piscisaureus authored
95 return 0;
b931c93 @ry uv_close returns void
ry authored
96 }
Something went wrong with that request. Please try again.