asyncengine 0.0.1.testing1 → 0.0.2.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (251) hide show
  1. data/README.markdown +3 -0
  2. data/Rakefile +38 -0
  3. data/asyncengine.gemspec +8 -4
  4. data/ext/asyncengine/ae_call_from_other_thread.c +106 -0
  5. data/ext/asyncengine/ae_call_from_other_thread.h +12 -0
  6. data/ext/asyncengine/ae_handle_common.c +193 -48
  7. data/ext/asyncengine/ae_handle_common.h +40 -13
  8. data/ext/asyncengine/ae_ip_utils.c +246 -0
  9. data/ext/asyncengine/ae_ip_utils.h +25 -0
  10. data/ext/asyncengine/ae_next_tick.c +81 -21
  11. data/ext/asyncengine/ae_next_tick.h +4 -2
  12. data/ext/asyncengine/ae_resolver.c +156 -0
  13. data/ext/asyncengine/ae_resolver.h +10 -0
  14. data/ext/asyncengine/ae_tcp.c +908 -0
  15. data/ext/asyncengine/ae_tcp.h +20 -0
  16. data/ext/asyncengine/ae_timer.c +355 -81
  17. data/ext/asyncengine/ae_timer.h +11 -4
  18. data/ext/asyncengine/ae_udp.c +579 -13
  19. data/ext/asyncengine/ae_udp.h +15 -2
  20. data/ext/asyncengine/ae_utils.c +192 -0
  21. data/ext/asyncengine/ae_utils.h +16 -0
  22. data/ext/asyncengine/asyncengine_ruby.c +469 -26
  23. data/ext/asyncengine/asyncengine_ruby.h +49 -11
  24. data/ext/asyncengine/debug.h +68 -0
  25. data/ext/asyncengine/extconf.rb +26 -2
  26. data/ext/asyncengine/ip_parser.c +5954 -0
  27. data/ext/asyncengine/ip_parser.h +16 -0
  28. data/ext/asyncengine/libuv/AUTHORS +16 -0
  29. data/ext/asyncengine/libuv/common.gypi +4 -4
  30. data/ext/asyncengine/libuv/config-mingw.mk +6 -6
  31. data/ext/asyncengine/libuv/config-unix.mk +13 -13
  32. data/ext/asyncengine/libuv/gyp_uv +5 -1
  33. data/ext/asyncengine/libuv/ibc_tests/exec_test.sh +8 -0
  34. data/ext/asyncengine/libuv/ibc_tests/uv_shutdown_write_issue.c +171 -0
  35. data/ext/asyncengine/libuv/ibc_tests/uv_tcp_close_while_connecting.c +102 -0
  36. data/ext/asyncengine/libuv/include/uv-private/ngx-queue.h +3 -1
  37. data/ext/asyncengine/libuv/include/uv-private/uv-unix.h +103 -50
  38. data/ext/asyncengine/libuv/include/uv-private/uv-win.h +76 -24
  39. data/ext/asyncengine/libuv/include/uv.h +353 -88
  40. data/ext/asyncengine/libuv/src/ares/ares__close_sockets.o +0 -0
  41. data/ext/asyncengine/libuv/src/ares/ares__get_hostent.o +0 -0
  42. data/ext/asyncengine/libuv/src/ares/ares__read_line.o +0 -0
  43. data/ext/asyncengine/libuv/src/ares/ares__timeval.o +0 -0
  44. data/ext/asyncengine/libuv/src/ares/ares_cancel.o +0 -0
  45. data/ext/asyncengine/libuv/src/ares/ares_data.o +0 -0
  46. data/ext/asyncengine/libuv/src/ares/ares_destroy.o +0 -0
  47. data/ext/asyncengine/libuv/src/ares/ares_expand_name.o +0 -0
  48. data/ext/asyncengine/libuv/src/ares/ares_expand_string.o +0 -0
  49. data/ext/asyncengine/libuv/src/ares/ares_fds.o +0 -0
  50. data/ext/asyncengine/libuv/src/ares/ares_free_hostent.o +0 -0
  51. data/ext/asyncengine/libuv/src/ares/ares_free_string.o +0 -0
  52. data/ext/asyncengine/libuv/src/ares/ares_gethostbyaddr.o +0 -0
  53. data/ext/asyncengine/libuv/src/ares/ares_gethostbyname.o +0 -0
  54. data/ext/asyncengine/libuv/src/ares/ares_getnameinfo.o +0 -0
  55. data/ext/asyncengine/libuv/src/ares/ares_getopt.o +0 -0
  56. data/ext/asyncengine/libuv/src/ares/ares_getsock.o +0 -0
  57. data/ext/asyncengine/libuv/src/ares/ares_init.o +0 -0
  58. data/ext/asyncengine/libuv/src/ares/ares_library_init.o +0 -0
  59. data/ext/asyncengine/libuv/src/ares/ares_llist.o +0 -0
  60. data/ext/asyncengine/libuv/src/ares/ares_mkquery.o +0 -0
  61. data/ext/asyncengine/libuv/src/ares/ares_nowarn.o +0 -0
  62. data/ext/asyncengine/libuv/src/ares/ares_options.o +0 -0
  63. data/ext/asyncengine/libuv/src/ares/ares_parse_a_reply.o +0 -0
  64. data/ext/asyncengine/libuv/src/ares/ares_parse_aaaa_reply.o +0 -0
  65. data/ext/asyncengine/libuv/src/ares/ares_parse_mx_reply.o +0 -0
  66. data/ext/asyncengine/libuv/src/ares/ares_parse_ns_reply.o +0 -0
  67. data/ext/asyncengine/libuv/src/ares/ares_parse_ptr_reply.o +0 -0
  68. data/ext/asyncengine/libuv/src/ares/ares_parse_srv_reply.o +0 -0
  69. data/ext/asyncengine/libuv/src/ares/ares_parse_txt_reply.o +0 -0
  70. data/ext/asyncengine/libuv/src/ares/ares_process.o +0 -0
  71. data/ext/asyncengine/libuv/src/ares/ares_query.o +0 -0
  72. data/ext/asyncengine/libuv/src/ares/ares_search.o +0 -0
  73. data/ext/asyncengine/libuv/src/ares/ares_send.o +0 -0
  74. data/ext/asyncengine/libuv/src/ares/ares_strcasecmp.o +0 -0
  75. data/ext/asyncengine/libuv/src/ares/ares_strdup.o +0 -0
  76. data/ext/asyncengine/libuv/src/ares/ares_strerror.o +0 -0
  77. data/ext/asyncengine/libuv/src/ares/ares_timeout.o +0 -0
  78. data/ext/asyncengine/libuv/src/ares/ares_version.o +0 -0
  79. data/ext/asyncengine/libuv/src/ares/ares_writev.o +0 -0
  80. data/ext/asyncengine/libuv/src/ares/bitncmp.o +0 -0
  81. data/ext/asyncengine/libuv/src/ares/inet_net_pton.o +0 -0
  82. data/ext/asyncengine/libuv/src/ares/inet_ntop.o +0 -0
  83. data/ext/asyncengine/libuv/src/cares.c +225 -0
  84. data/ext/asyncengine/libuv/src/cares.o +0 -0
  85. data/ext/asyncengine/libuv/src/fs-poll.c +237 -0
  86. data/ext/asyncengine/libuv/src/fs-poll.o +0 -0
  87. data/ext/asyncengine/libuv/src/unix/async.c +78 -17
  88. data/ext/asyncengine/libuv/src/unix/async.o +0 -0
  89. data/ext/asyncengine/libuv/src/unix/core.c +305 -213
  90. data/ext/asyncengine/libuv/src/unix/core.o +0 -0
  91. data/ext/asyncengine/libuv/src/unix/cygwin.c +1 -1
  92. data/ext/asyncengine/libuv/src/unix/darwin.c +2 -1
  93. data/ext/asyncengine/libuv/src/unix/dl.c +36 -44
  94. data/ext/asyncengine/libuv/src/unix/dl.o +0 -0
  95. data/ext/asyncengine/libuv/src/unix/eio/eio.o +0 -0
  96. data/ext/asyncengine/libuv/src/unix/error.c +6 -0
  97. data/ext/asyncengine/libuv/src/unix/error.o +0 -0
  98. data/ext/asyncengine/libuv/src/unix/ev/ev.c +8 -4
  99. data/ext/asyncengine/libuv/src/unix/ev/ev.o +0 -0
  100. data/ext/asyncengine/libuv/src/unix/freebsd.c +1 -1
  101. data/ext/asyncengine/libuv/src/unix/fs.c +25 -33
  102. data/ext/asyncengine/libuv/src/unix/fs.o +0 -0
  103. data/ext/asyncengine/libuv/src/unix/internal.h +50 -31
  104. data/ext/asyncengine/libuv/src/unix/kqueue.c +2 -7
  105. data/ext/asyncengine/libuv/src/unix/linux/core.o +0 -0
  106. data/ext/asyncengine/libuv/src/unix/linux/inotify.c +12 -14
  107. data/ext/asyncengine/libuv/src/unix/linux/inotify.o +0 -0
  108. data/ext/asyncengine/libuv/src/unix/linux/{core.c → linux-core.c} +1 -1
  109. data/ext/asyncengine/libuv/src/unix/linux/linux-core.o +0 -0
  110. data/ext/asyncengine/libuv/src/unix/linux/syscalls.c +147 -1
  111. data/ext/asyncengine/libuv/src/unix/linux/syscalls.h +39 -2
  112. data/ext/asyncengine/libuv/src/unix/linux/syscalls.o +0 -0
  113. data/ext/asyncengine/libuv/src/unix/loop-watcher.c +63 -0
  114. data/ext/asyncengine/libuv/src/unix/loop-watcher.o +0 -0
  115. data/ext/asyncengine/libuv/src/unix/loop.c +29 -6
  116. data/ext/asyncengine/libuv/src/unix/loop.o +0 -0
  117. data/ext/asyncengine/libuv/src/unix/netbsd.c +1 -1
  118. data/ext/asyncengine/libuv/src/unix/openbsd.c +1 -1
  119. data/ext/asyncengine/libuv/src/unix/pipe.c +31 -36
  120. data/ext/asyncengine/libuv/src/unix/pipe.o +0 -0
  121. data/ext/asyncengine/libuv/src/unix/poll.c +116 -0
  122. data/ext/asyncengine/libuv/src/unix/poll.o +0 -0
  123. data/ext/asyncengine/libuv/src/unix/process.c +193 -115
  124. data/ext/asyncengine/libuv/src/unix/process.o +0 -0
  125. data/ext/asyncengine/libuv/src/unix/stream.c +146 -153
  126. data/ext/asyncengine/libuv/src/unix/stream.o +0 -0
  127. data/ext/asyncengine/libuv/src/unix/sunos.c +45 -36
  128. data/ext/asyncengine/libuv/src/unix/tcp.c +6 -5
  129. data/ext/asyncengine/libuv/src/unix/tcp.o +0 -0
  130. data/ext/asyncengine/libuv/src/unix/thread.c +82 -25
  131. data/ext/asyncengine/libuv/src/unix/thread.o +0 -0
  132. data/ext/asyncengine/libuv/src/unix/timer.c +69 -58
  133. data/ext/asyncengine/libuv/src/unix/timer.o +0 -0
  134. data/ext/asyncengine/libuv/src/unix/tty.c +3 -3
  135. data/ext/asyncengine/libuv/src/unix/tty.o +0 -0
  136. data/ext/asyncengine/libuv/src/unix/udp.c +57 -66
  137. data/ext/asyncengine/libuv/src/unix/udp.o +0 -0
  138. data/ext/asyncengine/libuv/src/unix/uv-eio.c +33 -50
  139. data/ext/asyncengine/libuv/src/unix/uv-eio.o +0 -0
  140. data/ext/asyncengine/libuv/src/uv-common.c +68 -38
  141. data/ext/asyncengine/libuv/src/uv-common.h +104 -20
  142. data/ext/asyncengine/libuv/src/uv-common.o +0 -0
  143. data/ext/asyncengine/libuv/src/win/async.c +20 -17
  144. data/ext/asyncengine/libuv/src/win/core.c +44 -31
  145. data/ext/asyncengine/libuv/src/win/dl.c +40 -36
  146. data/ext/asyncengine/libuv/src/win/error.c +21 -1
  147. data/ext/asyncengine/libuv/src/win/fs-event.c +19 -21
  148. data/ext/asyncengine/libuv/src/win/fs.c +541 -189
  149. data/ext/asyncengine/libuv/src/win/getaddrinfo.c +56 -63
  150. data/ext/asyncengine/libuv/src/win/handle-inl.h +145 -0
  151. data/ext/asyncengine/libuv/src/win/handle.c +26 -101
  152. data/ext/asyncengine/libuv/src/win/internal.h +92 -107
  153. data/ext/asyncengine/libuv/src/win/loop-watcher.c +6 -14
  154. data/ext/asyncengine/libuv/src/win/pipe.c +78 -64
  155. data/ext/asyncengine/libuv/src/win/poll.c +618 -0
  156. data/ext/asyncengine/libuv/src/win/process-stdio.c +479 -0
  157. data/ext/asyncengine/libuv/src/win/process.c +147 -274
  158. data/ext/asyncengine/libuv/src/win/req-inl.h +225 -0
  159. data/ext/asyncengine/libuv/src/win/req.c +0 -149
  160. data/ext/asyncengine/libuv/src/{unix/check.c → win/stream-inl.h} +31 -42
  161. data/ext/asyncengine/libuv/src/win/stream.c +9 -43
  162. data/ext/asyncengine/libuv/src/win/tcp.c +200 -82
  163. data/ext/asyncengine/libuv/src/win/thread.c +42 -2
  164. data/ext/asyncengine/libuv/src/win/threadpool.c +3 -2
  165. data/ext/asyncengine/libuv/src/win/timer.c +13 -63
  166. data/ext/asyncengine/libuv/src/win/tty.c +26 -20
  167. data/ext/asyncengine/libuv/src/win/udp.c +26 -17
  168. data/ext/asyncengine/libuv/src/win/util.c +312 -167
  169. data/ext/asyncengine/libuv/src/win/winapi.c +16 -1
  170. data/ext/asyncengine/libuv/src/win/winapi.h +33 -9
  171. data/ext/asyncengine/libuv/src/win/winsock.c +88 -1
  172. data/ext/asyncengine/libuv/src/win/winsock.h +36 -3
  173. data/ext/asyncengine/libuv/test/benchmark-ares.c +16 -17
  174. data/ext/asyncengine/libuv/test/benchmark-fs-stat.c +164 -0
  175. data/ext/asyncengine/libuv/test/benchmark-list.h +9 -0
  176. data/ext/asyncengine/libuv/{src/unix/prepare.c → test/benchmark-loop-count.c} +42 -33
  177. data/ext/asyncengine/libuv/test/benchmark-million-timers.c +65 -0
  178. data/ext/asyncengine/libuv/test/benchmark-pound.c +1 -1
  179. data/ext/asyncengine/libuv/test/benchmark-sizes.c +2 -0
  180. data/ext/asyncengine/libuv/test/benchmark-spawn.c +7 -1
  181. data/ext/asyncengine/libuv/test/benchmark-udp-packet-storm.c +1 -1
  182. data/ext/asyncengine/libuv/test/echo-server.c +8 -0
  183. data/ext/asyncengine/libuv/test/run-tests.c +30 -0
  184. data/ext/asyncengine/libuv/test/runner-unix.c +6 -26
  185. data/ext/asyncengine/libuv/test/runner-win.c +5 -63
  186. data/ext/asyncengine/libuv/test/runner.c +10 -1
  187. data/ext/asyncengine/libuv/test/task.h +0 -8
  188. data/ext/asyncengine/libuv/test/test-async.c +43 -141
  189. data/ext/asyncengine/libuv/test/test-callback-order.c +76 -0
  190. data/ext/asyncengine/libuv/test/test-counters-init.c +2 -3
  191. data/ext/asyncengine/libuv/test/test-dlerror.c +17 -8
  192. data/ext/asyncengine/libuv/test/test-fs-event.c +31 -39
  193. data/ext/asyncengine/libuv/test/test-fs-poll.c +146 -0
  194. data/ext/asyncengine/libuv/test/test-fs.c +114 -2
  195. data/ext/asyncengine/libuv/test/test-gethostbyname.c +8 -8
  196. data/ext/asyncengine/libuv/test/test-hrtime.c +18 -15
  197. data/ext/asyncengine/libuv/test/test-ipc.c +8 -2
  198. data/ext/asyncengine/libuv/test/test-list.h +59 -9
  199. data/ext/asyncengine/libuv/test/test-loop-handles.c +2 -25
  200. data/ext/asyncengine/libuv/{src/unix/idle.c → test/test-poll-close.c} +37 -39
  201. data/ext/asyncengine/libuv/test/test-poll.c +573 -0
  202. data/ext/asyncengine/libuv/test/test-ref.c +79 -63
  203. data/ext/asyncengine/libuv/test/test-run-once.c +15 -11
  204. data/ext/asyncengine/libuv/test/test-semaphore.c +111 -0
  205. data/ext/asyncengine/libuv/test/test-spawn.c +368 -20
  206. data/ext/asyncengine/libuv/test/test-stdio-over-pipes.c +25 -35
  207. data/ext/asyncengine/libuv/test/test-tcp-close-while-connecting.c +80 -0
  208. data/ext/asyncengine/libuv/test/test-tcp-close.c +1 -1
  209. data/ext/asyncengine/libuv/test/test-tcp-connect-error-after-write.c +95 -0
  210. data/ext/asyncengine/libuv/test/test-tcp-connect-timeout.c +85 -0
  211. data/ext/asyncengine/libuv/test/test-tcp-shutdown-after-write.c +131 -0
  212. data/ext/asyncengine/libuv/test/test-tcp-write-error.c +2 -2
  213. data/ext/asyncengine/libuv/test/test-tcp-writealot.c +29 -54
  214. data/ext/asyncengine/libuv/test/test-timer-again.c +1 -1
  215. data/ext/asyncengine/libuv/test/test-timer.c +23 -1
  216. data/ext/asyncengine/libuv/test/test-udp-options.c +1 -1
  217. data/ext/asyncengine/libuv/test/{test-eio-overflow.c → test-walk-handles.c} +31 -44
  218. data/ext/asyncengine/libuv/uv.gyp +26 -9
  219. data/ext/asyncengine/rb_utilities.c +54 -0
  220. data/ext/asyncengine/rb_utilities.h +63 -0
  221. data/lib/asyncengine.rb +45 -38
  222. data/lib/asyncengine/asyncengine_ext.so +0 -0
  223. data/lib/asyncengine/debug.rb +37 -0
  224. data/lib/asyncengine/handle.rb +9 -0
  225. data/lib/asyncengine/tcp.rb +28 -0
  226. data/lib/asyncengine/timer.rb +18 -28
  227. data/lib/asyncengine/udp.rb +29 -0
  228. data/lib/asyncengine/utils.rb +32 -0
  229. data/lib/asyncengine/uv_error.rb +17 -0
  230. data/lib/asyncengine/version.rb +9 -1
  231. data/test/ae_test_helper.rb +62 -0
  232. data/test/test_basic.rb +169 -0
  233. data/test/test_call_from_other_thread.rb +55 -0
  234. data/test/test_error.rb +92 -0
  235. data/test/test_ip_utils.rb +44 -0
  236. data/test/test_next_tick.rb +37 -0
  237. data/test/test_resolver.rb +51 -0
  238. data/test/test_threads.rb +69 -0
  239. data/test/test_timer.rb +95 -0
  240. data/test/test_udp.rb +216 -0
  241. data/test/test_utils.rb +49 -0
  242. metadata +84 -57
  243. data/ext/asyncengine/libuv/mkmf.log +0 -24
  244. data/ext/asyncengine/libuv/src/unix/cares.c +0 -194
  245. data/ext/asyncengine/libuv/src/unix/cares.o +0 -0
  246. data/ext/asyncengine/libuv/src/unix/check.o +0 -0
  247. data/ext/asyncengine/libuv/src/unix/idle.o +0 -0
  248. data/ext/asyncengine/libuv/src/unix/prepare.o +0 -0
  249. data/ext/asyncengine/libuv/src/win/cares.c +0 -290
  250. data/lib/asyncengine/errors.rb +0 -5
  251. data/lib/asyncengine/next_tick.rb +0 -24
@@ -19,6 +19,7 @@
19
19
  * IN THE SOFTWARE.
20
20
  */
21
21
 
22
+ #include <stdio.h>
22
23
  #include <string.h>
23
24
 
24
25
  #include "runner.h"
@@ -28,7 +29,10 @@ char executable_path[PATHMAX] = { '\0' };
28
29
 
29
30
 
30
31
  static void log_progress(int total, int passed, int failed, const char* name) {
31
- LOGF("[%% %3d|+ %3d|- %3d]: %s", (passed + failed) / total * 100,
32
+ if (total == 0)
33
+ total = 1;
34
+
35
+ LOGF("[%% %3d|+ %3d|- %3d]: %s", (int) ((passed + failed) / ((double) total) * 100.0),
32
36
  passed, failed, name);
33
37
  }
34
38
 
@@ -89,6 +93,11 @@ int run_test(const char* test, int timeout, int benchmark_output) {
89
93
  main_proc = NULL;
90
94
  process_count = 0;
91
95
 
96
+ #ifndef _WIN32
97
+ /* Clean up stale socket from previous run. */
98
+ remove(TEST_PIPENAME);
99
+ #endif
100
+
92
101
  /* If it's a helper the user asks for, start it directly. */
93
102
  for (task = TASKS; task->main; task++) {
94
103
  if (task->is_helper && strcmp(test, task->process_name) == 0) {
@@ -103,14 +103,6 @@ typedef enum {
103
103
  int run_helper_##name()
104
104
 
105
105
 
106
- /* Create a thread. Returns the thread identifier, or 0 on failure. */
107
- uintptr_t uv_create_thread(void (*entry)(void* arg), void* arg);
108
-
109
- /* Wait for a thread to terminate. Should return 0 if the thread ended, -1 on
110
- * error.
111
- */
112
- int uv_wait_thread(uintptr_t thread_id);
113
-
114
106
  /* Pause the calling thread for a number of milliseconds. */
115
107
  void uv_sleep(int msec);
116
108
 
@@ -24,192 +24,94 @@
24
24
  #include <stdio.h>
25
25
  #include <stdlib.h>
26
26
 
27
+ static uv_thread_t thread;
28
+ static uv_mutex_t mutex;
27
29
 
28
- static uv_prepare_t prepare_handle;
30
+ static uv_prepare_t prepare;
31
+ static uv_async_t async;
29
32
 
30
- static uv_async_t async1_handle;
31
- /* static uv_handle_t async2_handle; */
33
+ static volatile int async_cb_called;
34
+ static int prepare_cb_called;
35
+ static int close_cb_called;
32
36
 
33
- static int prepare_cb_called = 0;
34
37
 
35
- static volatile int async1_cb_called = 0;
36
- static int async1_closed = 0;
37
- /* static volatile int async2_cb_called = 0; */
38
-
39
- static int close_cb_called = 0;
40
-
41
- static uintptr_t thread1_id = 0;
42
- #if 0
43
- static uintptr_t thread2_id = 0;
44
- static uintptr_t thread3_id = 0;
45
- #endif
46
-
47
-
48
- /* Thread 1 makes sure that async1_cb_called reaches 3 before exiting. */
49
- void thread1_entry(void *arg) {
50
- uv_sleep(50);
51
-
52
- while (1) {
53
- switch (async1_cb_called) {
54
- case 0:
55
- uv_async_send(&async1_handle);
56
- break;
57
-
58
- case 1:
59
- uv_async_send(&async1_handle);
60
- break;
61
-
62
- case 2:
63
- uv_async_send(&async1_handle);
64
- break;
65
-
66
- default:
67
- return;
68
- }
69
- }
70
- }
71
-
72
- #if 0
73
- /* Thread 2 calls uv_async_send on async_handle_2 8 times. */
74
- void thread2_entry(void *arg) {
75
- int i;
76
-
77
- while (1) {
78
- switch (async1_cb_called) {
79
- case 0:
80
- uv_async_send(&async2_handle);
81
- break;
38
+ void thread_cb(void *arg) {
39
+ int n;
40
+ int r;
82
41
 
83
- case 1:
84
- uv_async_send(&async2_handle);
85
- break;
42
+ for (;;) {
43
+ uv_mutex_lock(&mutex);
44
+ n = async_cb_called;
45
+ uv_mutex_unlock(&mutex);
86
46
 
87
- case 2:
88
- uv_async_send(&async2_handle);
89
- break;
47
+ if (n == 3) {
48
+ break;
90
49
  }
91
- uv_sleep(5);
92
- }
93
50
 
94
- if (async1_cb_called == 20) {
95
- uv_close(handle);
51
+ r = uv_async_send(&async);
52
+ ASSERT(r == 0);
96
53
  }
97
54
  }
98
55
 
99
56
 
100
- /* Thread 3 calls uv_async_send on async_handle_2 8 times
101
- * after waiting half a second first.
102
- */
103
- void thread3_entry(void *arg) {
104
- int i;
105
-
106
- for (i = 0; i < 8; i++) {
107
- uv_async_send(&async2_handle);
108
- }
109
- }
110
- #endif
111
-
112
-
113
57
  static void close_cb(uv_handle_t* handle) {
114
58
  ASSERT(handle != NULL);
115
59
  close_cb_called++;
116
60
  }
117
61
 
118
62
 
119
- static void async1_cb(uv_async_t* handle, int status) {
120
- ASSERT(handle == &async1_handle);
121
- ASSERT(status == 0);
122
-
123
- async1_cb_called++;
124
- printf("async1_cb #%d\n", async1_cb_called);
125
-
126
- if (async1_cb_called > 2 && !async1_closed) {
127
- async1_closed = 1;
128
- uv_close((uv_handle_t*)handle, close_cb);
129
- }
130
- }
131
-
63
+ static void async_cb(uv_async_t* handle, int status) {
64
+ int n;
132
65
 
133
- #if 0
134
- static void async2_cb(uv_handle_t* handle, int status) {
135
- ASSERT(handle == &async2_handle);
66
+ ASSERT(handle == &async);
136
67
  ASSERT(status == 0);
137
68
 
138
- async2_cb_called++;
139
- printf("async2_cb #%d\n", async2_cb_called);
69
+ uv_mutex_lock(&mutex);
70
+ n = ++async_cb_called;
71
+ uv_mutex_unlock(&mutex);
140
72
 
141
- if (async2_cb_called == 16) {
142
- uv_close(handle);
73
+ if (n == 3) {
74
+ uv_close((uv_handle_t*)&async, close_cb);
75
+ uv_close((uv_handle_t*)&prepare, close_cb);
143
76
  }
144
77
  }
145
- #endif
146
78
 
147
79
 
148
80
  static void prepare_cb(uv_prepare_t* handle, int status) {
149
- ASSERT(handle == &prepare_handle);
150
- ASSERT(status == 0);
151
-
152
- switch (prepare_cb_called) {
153
- case 0:
154
- thread1_id = uv_create_thread(thread1_entry, NULL);
155
- ASSERT(thread1_id != 0);
156
- break;
157
-
158
- #if 0
159
- case 1:
160
- thread2_id = uv_create_thread(thread2_entry, NULL);
161
- ASSERT(thread2_id != 0);
162
- break;
163
-
164
- case 2:
165
- thread3_id = uv_create_thread(thread3_entry, NULL);
166
- ASSERT(thread3_id != 0);
167
- break;
168
- #endif
81
+ int r;
169
82
 
170
- case 1:
171
- uv_close((uv_handle_t*)handle, close_cb);
172
- break;
83
+ ASSERT(handle == &prepare);
84
+ ASSERT(status == 0);
173
85
 
174
- default:
175
- FATAL("Should never get here");
176
- }
86
+ if (prepare_cb_called++)
87
+ return;
177
88
 
178
- prepare_cb_called++;
89
+ r = uv_thread_create(&thread, thread_cb, NULL);
90
+ ASSERT(r == 0);
91
+ uv_mutex_unlock(&mutex);
179
92
  }
180
93
 
181
94
 
182
95
  TEST_IMPL(async) {
183
96
  int r;
184
97
 
185
- r = uv_prepare_init(uv_default_loop(), &prepare_handle);
186
- ASSERT(r == 0);
187
- r = uv_prepare_start(&prepare_handle, prepare_cb);
98
+ r = uv_mutex_init(&mutex);
188
99
  ASSERT(r == 0);
100
+ uv_mutex_lock(&mutex);
189
101
 
190
- r = uv_async_init(uv_default_loop(), &async1_handle, async1_cb);
102
+ r = uv_prepare_init(uv_default_loop(), &prepare);
191
103
  ASSERT(r == 0);
192
-
193
- #if 0
194
- r = uv_async_init(&async2_handle, async2_cb, close_cb, NULL);
104
+ r = uv_prepare_start(&prepare, prepare_cb);
195
105
  ASSERT(r == 0);
196
- #endif
197
106
 
198
- r = uv_run(uv_default_loop());
107
+ r = uv_async_init(uv_default_loop(), &async, async_cb);
199
108
  ASSERT(r == 0);
200
109
 
201
- r = uv_wait_thread(thread1_id);
202
- ASSERT(r == 0);
203
- #if 0
204
- r = uv_wait_thread(thread2_id);
205
- ASSERT(r == 0);
206
- r = uv_wait_thread(thread3_id);
110
+ r = uv_run(uv_default_loop());
207
111
  ASSERT(r == 0);
208
- #endif
209
112
 
210
- ASSERT(prepare_cb_called == 2);
211
- ASSERT(async1_cb_called > 2);
212
- /* ASSERT(async2_cb_called = 16); */
113
+ ASSERT(prepare_cb_called > 0);
114
+ ASSERT(async_cb_called == 3);
213
115
  ASSERT(close_cb_called == 2);
214
116
 
215
117
  return 0;
@@ -0,0 +1,76 @@
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
+ static int idle_cb_called;
26
+ static int timer_cb_called;
27
+
28
+ static uv_idle_t idle_handle;
29
+ static uv_timer_t timer_handle;
30
+
31
+
32
+ /* idle_cb should run before timer_cb */
33
+ static void idle_cb(uv_idle_t* handle, int status) {
34
+ ASSERT(idle_cb_called == 0);
35
+ ASSERT(timer_cb_called == 0);
36
+ uv_idle_stop(handle);
37
+ idle_cb_called++;
38
+ }
39
+
40
+
41
+ static void timer_cb(uv_timer_t* handle, int status) {
42
+ ASSERT(idle_cb_called == 1);
43
+ ASSERT(timer_cb_called == 0);
44
+ uv_timer_stop(handle);
45
+ timer_cb_called++;
46
+ }
47
+
48
+
49
+ static void next_tick(uv_idle_t* handle, int status) {
50
+ uv_loop_t* loop = handle->loop;
51
+ uv_idle_stop(handle);
52
+ uv_idle_init(loop, &idle_handle);
53
+ uv_idle_start(&idle_handle, idle_cb);
54
+ uv_timer_init(loop, &timer_handle);
55
+ uv_timer_start(&timer_handle, timer_cb, 0, 0);
56
+ }
57
+
58
+
59
+ TEST_IMPL(callback_order) {
60
+ uv_loop_t* loop;
61
+ uv_idle_t idle;
62
+
63
+ loop = uv_default_loop();
64
+ uv_idle_init(loop, &idle);
65
+ uv_idle_start(&idle, next_tick);
66
+
67
+ ASSERT(idle_cb_called == 0);
68
+ ASSERT(timer_cb_called == 0);
69
+
70
+ uv_run(loop);
71
+
72
+ ASSERT(idle_cb_called == 1);
73
+ ASSERT(timer_cb_called == 1);
74
+
75
+ return 0;
76
+ }
@@ -78,7 +78,7 @@ static void create_dir(uv_loop_t* loop, const char* name) {
78
78
  uv_fs_t req;
79
79
  r = uv_fs_rmdir(loop, &req, name, NULL);
80
80
  r = uv_fs_mkdir(loop, &req, name, 0755, NULL);
81
- ASSERT(r == 0);
81
+ ASSERT(r == 0 || uv_last_error(loop).code == UV_EEXIST);
82
82
  uv_fs_req_cleanup(&req);
83
83
  }
84
84
 
@@ -208,8 +208,7 @@ TEST_IMPL(counters_init) {
208
208
  r = uv_fs_event_init(uv_default_loop(), &fs_event, "watch_dir", NULL, 0);
209
209
  ASSERT(r == 0);
210
210
  ASSERT(uv_default_loop()->counters.fs_event_init == ++fs_event_init_prev);
211
- r = uv_fs_rmdir(uv_default_loop(), &fs_req, "watch_dir", NULL);
212
- ASSERT(r == 0);
211
+ uv_fs_rmdir(uv_default_loop(), &fs_req, "watch_dir", NULL);
213
212
  uv_fs_req_cleanup(&fs_req);
214
213
 
215
214
  return 0;
@@ -23,8 +23,12 @@
23
23
  #include "task.h"
24
24
  #include <string.h>
25
25
 
26
- const char* path = "test/fixtures/load_error.node";
27
- const char* msg;
26
+
27
+ TEST_IMPL(dlerror) {
28
+ const char* path = "test/fixtures/load_error.node";
29
+ const char* msg;
30
+ uv_lib_t lib;
31
+ int r;
28
32
 
29
33
  #ifdef __linux__
30
34
  const char* dlerror_desc = "file too short";
@@ -36,14 +40,19 @@ const char* msg;
36
40
  const char* dlerror_desc = "";
37
41
  #endif
38
42
 
39
- uv_lib_t lib;
40
- uv_err_t r;
41
-
42
- TEST_IMPL(dlerror) {
43
43
  r = uv_dlopen(path, &lib);
44
- msg = uv_dlerror(lib);
44
+ ASSERT(r == -1);
45
+
46
+ msg = uv_dlerror(&lib);
45
47
  ASSERT(msg != NULL);
46
48
  ASSERT(strstr(msg, dlerror_desc) != NULL);
47
- uv_dlerror_free(lib, msg);
49
+
50
+ /* Should return the same error twice in a row. */
51
+ msg = uv_dlerror(&lib);
52
+ ASSERT(msg != NULL);
53
+ ASSERT(strstr(msg, dlerror_desc) != NULL);
54
+
55
+ uv_dlclose(&lib);
56
+
48
57
  return 0;
49
58
  }
@@ -38,6 +38,26 @@ static int close_cb_called = 0;
38
38
  static int fs_event_cb_called = 0;
39
39
  static int timer_cb_touch_called = 0;
40
40
 
41
+ static void cleanup_watch_dir() {
42
+ uv_loop_t* loop = uv_default_loop();
43
+ uv_fs_t readdir_req;
44
+ int i, r;
45
+ char *buffer, *name;
46
+
47
+ r = uv_fs_readdir(loop, &readdir_req, "watch_dir", 0, NULL);
48
+ buffer = readdir_req.ptr;
49
+ uv_chdir("watch_dir");
50
+ for (i = 0; i < readdir_req.result; i++) {
51
+ name = buffer;
52
+ r = remove(name);
53
+ ASSERT(r == 0);
54
+ buffer += strlen(name) + 1;
55
+ }
56
+ uv_chdir("..");
57
+ r = remove("watch_dir");
58
+ ASSERT(r == 0 || uv_last_error(loop).code == UV_ENOENT);
59
+ }
60
+
41
61
  static void create_dir(uv_loop_t* loop, const char* name) {
42
62
  int r;
43
63
  uv_fs_t req;
@@ -160,14 +180,11 @@ static void timer_cb_touch(uv_timer_t* timer, int status) {
160
180
  }
161
181
 
162
182
  TEST_IMPL(fs_event_watch_dir) {
163
- uv_fs_t fs_req;
164
183
  uv_loop_t* loop = uv_default_loop();
165
184
  int r;
166
185
 
167
186
  /* Setup */
168
- uv_fs_unlink(loop, &fs_req, "watch_dir/file1", NULL);
169
- uv_fs_unlink(loop, &fs_req, "watch_dir/file2", NULL);
170
- uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);
187
+ cleanup_watch_dir();
171
188
  create_dir(loop, "watch_dir");
172
189
 
173
190
  r = uv_fs_event_init(loop, &fs_event, "watch_dir", fs_event_cb_dir, 0);
@@ -184,22 +201,15 @@ TEST_IMPL(fs_event_watch_dir) {
184
201
  ASSERT(close_cb_called == 2);
185
202
 
186
203
  /* Cleanup */
187
- r = uv_fs_unlink(loop, &fs_req, "watch_dir/file1", NULL);
188
- r = uv_fs_unlink(loop, &fs_req, "watch_dir/file2", NULL);
189
- r = uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);
190
-
204
+ cleanup_watch_dir();
191
205
  return 0;
192
206
  }
193
207
 
194
208
  TEST_IMPL(fs_event_watch_file) {
195
- uv_fs_t fs_req;
196
209
  uv_loop_t* loop = uv_default_loop();
197
210
  int r;
198
211
 
199
212
  /* Setup */
200
- uv_fs_unlink(loop, &fs_req, "watch_dir/file1", NULL);
201
- uv_fs_unlink(loop, &fs_req, "watch_dir/file2", NULL);
202
- uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);
203
213
  create_dir(loop, "watch_dir");
204
214
  create_file(loop, "watch_dir/file1");
205
215
  create_file(loop, "watch_dir/file2");
@@ -218,10 +228,7 @@ TEST_IMPL(fs_event_watch_file) {
218
228
  ASSERT(close_cb_called == 2);
219
229
 
220
230
  /* Cleanup */
221
- r = uv_fs_unlink(loop, &fs_req, "watch_dir/file1", NULL);
222
- r = uv_fs_unlink(loop, &fs_req, "watch_dir/file2", NULL);
223
- r = uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);
224
-
231
+ cleanup_watch_dir();
225
232
  return 0;
226
233
  }
227
234
 
@@ -264,13 +271,11 @@ TEST_IMPL(fs_event_watch_file_current_dir) {
264
271
 
265
272
 
266
273
  TEST_IMPL(fs_event_no_callback_on_close) {
267
- uv_fs_t fs_req;
268
274
  uv_loop_t* loop = uv_default_loop();
269
275
  int r;
270
276
 
271
277
  /* Setup */
272
- uv_fs_unlink(loop, &fs_req, "watch_dir/file1", NULL);
273
- uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);
278
+ cleanup_watch_dir();
274
279
  create_dir(loop, "watch_dir");
275
280
  create_file(loop, "watch_dir/file1");
276
281
 
@@ -289,8 +294,7 @@ TEST_IMPL(fs_event_no_callback_on_close) {
289
294
  ASSERT(close_cb_called == 1);
290
295
 
291
296
  /* Cleanup */
292
- r = uv_fs_unlink(loop, &fs_req, "watch_dir/file1", NULL);
293
- r = uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);
297
+ cleanup_watch_dir();
294
298
 
295
299
  return 0;
296
300
  }
@@ -338,11 +342,12 @@ TEST_IMPL(fs_event_immediate_close) {
338
342
 
339
343
  TEST_IMPL(fs_event_close_with_pending_event) {
340
344
  uv_loop_t* loop;
341
- uv_fs_t fs_req;
342
345
  int r;
343
346
 
344
347
  loop = uv_default_loop();
345
348
 
349
+ cleanup_watch_dir();
350
+
346
351
  create_dir(loop, "watch_dir");
347
352
  create_file(loop, "watch_dir/file");
348
353
 
@@ -359,10 +364,7 @@ TEST_IMPL(fs_event_close_with_pending_event) {
359
364
  ASSERT(close_cb_called == 1);
360
365
 
361
366
  /* Clean up */
362
- r = uv_fs_unlink(loop, &fs_req, "watch_dir/file", NULL);
363
- ASSERT(r == 0);
364
- r = uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);
365
- ASSERT(r == 0);
367
+ cleanup_watch_dir();
366
368
 
367
369
  return 0;
368
370
  }
@@ -395,11 +397,12 @@ static void fs_event_cb_close(uv_fs_event_t* handle, const char* filename,
395
397
 
396
398
  TEST_IMPL(fs_event_close_in_callback) {
397
399
  uv_loop_t* loop;
398
- uv_fs_t fs_req;
399
400
  int r;
400
401
 
401
402
  loop = uv_default_loop();
402
403
 
404
+ cleanup_watch_dir();
405
+
403
406
  create_dir(loop, "watch_dir");
404
407
  create_file(loop, "watch_dir/file1");
405
408
  create_file(loop, "watch_dir/file2");
@@ -423,18 +426,7 @@ TEST_IMPL(fs_event_close_in_callback) {
423
426
  ASSERT(fs_event_cb_called == 3);
424
427
 
425
428
  /* Clean up */
426
- r = uv_fs_unlink(loop, &fs_req, "watch_dir/file1", NULL);
427
- ASSERT(r == 0);
428
- r = uv_fs_unlink(loop, &fs_req, "watch_dir/file2", NULL);
429
- ASSERT(r == 0);
430
- r = uv_fs_unlink(loop, &fs_req, "watch_dir/file3", NULL);
431
- ASSERT(r == 0);
432
- r = uv_fs_unlink(loop, &fs_req, "watch_dir/file4", NULL);
433
- ASSERT(r == 0);
434
- r = uv_fs_unlink(loop, &fs_req, "watch_dir/file5", NULL);
435
- ASSERT(r == 0);
436
- r = uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);
437
- ASSERT(r == 0);
429
+ cleanup_watch_dir();
438
430
 
439
431
  return 0;
440
432
  }