ext/libuv/test/test-fs-event.c in libuv-2.0.8 vs ext/libuv/test/test-fs-event.c in libuv-2.0.9
- old
+ new
@@ -51,11 +51,19 @@
static char fs_event_filename[PATH_MAX];
#else
static char fs_event_filename[1024];
#endif /* defined(PATH_MAX) */
static int timer_cb_touch_called;
+static int timer_cb_exact_called;
+static void fs_event_fail(uv_fs_event_t* handle,
+ const char* filename,
+ int events,
+ int status) {
+ ASSERT(0 && "should never be called");
+}
+
static void create_dir(const char* name) {
int r;
uv_fs_t req;
r = uv_fs_mkdir(NULL, &req, name, 0755, NULL);
ASSERT(r == 0 || r == UV_EEXIST);
@@ -343,10 +351,25 @@
uv_close((uv_handle_t*)timer, NULL);
touch_file("watch_file");
timer_cb_touch_called++;
}
+static void timer_cb_exact(uv_timer_t* handle) {
+ int r;
+
+ if (timer_cb_exact_called == 0) {
+ touch_file("watch_dir/file.js");
+ } else {
+ uv_close((uv_handle_t*)handle, NULL);
+ r = uv_fs_event_stop(&fs_event);
+ ASSERT(r == 0);
+ uv_close((uv_handle_t*) &fs_event, NULL);
+ }
+
+ ++timer_cb_exact_called;
+}
+
static void timer_cb_watch_twice(uv_timer_t* handle) {
uv_fs_event_t* handles = handle->data;
uv_close((uv_handle_t*) (handles + 0), NULL);
uv_close((uv_handle_t*) (handles + 1), NULL);
uv_close((uv_handle_t*) handle, NULL);
@@ -465,10 +488,49 @@
MAKE_VALGRIND_HAPPY();
return 0;
}
+TEST_IMPL(fs_event_watch_file_exact_path) {
+ /*
+ This test watches a file named "file.jsx" and modifies a file named
+ "file.js". The test verifies that no events occur for file.jsx.
+ */
+ uv_loop_t* loop;
+ int r;
+
+ loop = uv_default_loop();
+
+ /* Setup */
+ remove("watch_dir/file.js");
+ remove("watch_dir/file.jsx");
+ remove("watch_dir/");
+ create_dir("watch_dir");
+ create_file("watch_dir/file.js");
+ create_file("watch_dir/file.jsx");
+
+ r = uv_fs_event_init(loop, &fs_event);
+ ASSERT(r == 0);
+ r = uv_fs_event_start(&fs_event, fs_event_fail, "watch_dir/file.jsx", 0);
+ ASSERT(r == 0);
+ r = uv_timer_init(loop, &timer);
+ ASSERT(r == 0);
+ r = uv_timer_start(&timer, timer_cb_exact, 100, 100);
+ ASSERT(r == 0);
+ r = uv_run(loop, UV_RUN_DEFAULT);
+ ASSERT(r == 0);
+ ASSERT(timer_cb_exact_called == 2);
+
+ /* Cleanup */
+ remove("watch_dir/file.js");
+ remove("watch_dir/file.jsx");
+ remove("watch_dir/");
+
+ MAKE_VALGRIND_HAPPY();
+ return 0;
+}
+
TEST_IMPL(fs_event_watch_file_twice) {
const char path[] = "test/fixtures/empty_file";
uv_fs_event_t watchers[2];
uv_timer_t timer;
uv_loop_t* loop;
@@ -509,11 +571,11 @@
r = uv_timer_init(loop, &timer);
ASSERT(r == 0);
- r = uv_timer_start(&timer, timer_cb_touch, 10, 0);
+ r = uv_timer_start(&timer, timer_cb_touch, 100, 0);
ASSERT(r == 0);
ASSERT(timer_cb_touch_called == 0);
ASSERT(fs_event_cb_called == 0);
ASSERT(close_cb_called == 0);
@@ -624,16 +686,10 @@
MAKE_VALGRIND_HAPPY();
return 0;
}
-static void fs_event_fail(uv_fs_event_t* handle, const char* filename,
- int events, int status) {
- ASSERT(0 && "should never be called");
-}
-
-
static void timer_cb(uv_timer_t* handle) {
int r;
r = uv_fs_event_init(handle->loop, &fs_event);
ASSERT(r == 0);
@@ -696,22 +752,23 @@
MAKE_VALGRIND_HAPPY();
return 0;
}
-#if defined(HAVE_KQUEUE)
+#if defined(HAVE_KQUEUE) || defined(_AIX)
/* kqueue doesn't register fs events if you don't have an active watcher.
* The file descriptor needs to be part of the kqueue set of interest and
* that's not the case until we actually enter the event loop.
+ * This is also observed on AIX with ahafs.
*/
TEST_IMPL(fs_event_close_in_callback) {
- fprintf(stderr, "Skipping test, doesn't work with kqueue.\n");
+ fprintf(stderr, "Skipping test, doesn't work with kqueue and AIX.\n");
return 0;
}
-#else /* !HAVE_KQUEUE */
+#else /* !HAVE_KQUEUE || !_AIX */
static void fs_event_cb_close(uv_fs_event_t* handle, const char* filename,
int events, int status) {
ASSERT(status == 0);
@@ -764,10 +821,10 @@
MAKE_VALGRIND_HAPPY();
return 0;
}
-#endif /* HAVE_KQUEUE */
+#endif /* HAVE_KQUEUE || _AIX */
TEST_IMPL(fs_event_start_and_close) {
uv_loop_t* loop;
uv_fs_event_t fs_event1;
uv_fs_event_t fs_event2;