Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
test: add failing fs_event test
Browse files Browse the repository at this point in the history
Watches the same file twice. Fails on Linux with a segmentation fault.
  • Loading branch information
bnoordhuis committed Jul 28, 2012
1 parent 22f004d commit b5b8ead
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/test-fs-event.c
Expand Up @@ -85,6 +85,13 @@ static void close_cb(uv_handle_t* handle) {
close_cb_called++;
}

static void fail_cb(uv_fs_event_t* handle,
const char* path,
int events,
int status) {
ASSERT(0 && "fail_cb called");
}

static void fs_event_cb_dir(uv_fs_event_t* handle, const char* filename,
int events, int status) {
++fs_event_cb_called;
Expand Down Expand Up @@ -159,6 +166,13 @@ static void timer_cb_touch(uv_timer_t* timer, int status) {
timer_cb_touch_called++;
}

static void timer_cb_watch_twice(uv_timer_t* handle, int status) {
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);
}

TEST_IMPL(fs_event_watch_dir) {
uv_fs_t fs_req;
uv_loop_t* loop = uv_default_loop();
Expand Down Expand Up @@ -225,6 +239,24 @@ TEST_IMPL(fs_event_watch_file) {
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;

loop = uv_default_loop();
timer.data = watchers;

ASSERT(0 == uv_fs_event_init(loop, watchers + 0, path, fail_cb, 0));
ASSERT(0 == uv_fs_event_init(loop, watchers + 1, path, fail_cb, 0));
ASSERT(0 == uv_timer_init(loop, &timer));
ASSERT(0 == uv_timer_start(&timer, timer_cb_watch_twice, 10, 0));
ASSERT(0 == uv_run(loop));

return 0;
}

TEST_IMPL(fs_event_watch_file_current_dir) {
uv_timer_t timer;
uv_loop_t* loop;
Expand Down
2 changes: 2 additions & 0 deletions test/test-list.h
Expand Up @@ -158,6 +158,7 @@ TEST_DECLARE (fs_stat_missing_path)
TEST_DECLARE (fs_read_file_eof)
TEST_DECLARE (fs_event_watch_dir)
TEST_DECLARE (fs_event_watch_file)
TEST_DECLARE (fs_event_watch_file_twice)
TEST_DECLARE (fs_event_watch_file_current_dir)
TEST_DECLARE (fs_event_no_callback_on_close)
TEST_DECLARE (fs_event_immediate_close)
Expand Down Expand Up @@ -396,6 +397,7 @@ TASK_LIST_START
TEST_ENTRY (fs_file_open_append)
TEST_ENTRY (fs_event_watch_dir)
TEST_ENTRY (fs_event_watch_file)
TEST_ENTRY (fs_event_watch_file_twice)
TEST_ENTRY (fs_event_watch_file_current_dir)
TEST_ENTRY (fs_event_no_callback_on_close)
TEST_ENTRY (fs_event_immediate_close)
Expand Down

0 comments on commit b5b8ead

Please sign in to comment.