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

Commit

Permalink
Browse files Browse the repository at this point in the history
Revert "test: improve clean-up in test-fs-event"
There were too many errors in this commits; it totally broke on
Windows. Besides, when the moon is dark, the cleanup code could delete
some random files from my hard drive.

This reverts commit 7573f4a.
  • Loading branch information
piscisaureus committed Jun 29, 2012
1 parent 5ee80f1 commit e9b17bc
Showing 1 changed file with 39 additions and 31 deletions.
70 changes: 39 additions & 31 deletions test/test-fs-event.c
Expand Up @@ -38,26 +38,6 @@ static int close_cb_called = 0;
static int fs_event_cb_called = 0;
static int timer_cb_touch_called = 0;

static void cleanup_watch_dir() {
uv_loop_t* loop = uv_default_loop();
uv_fs_t readdir_req;
int i, r;
char *buffer, *name;

r = uv_fs_readdir(loop, &readdir_req, "watch_dir", 0, NULL);
buffer = readdir_req.ptr;
uv_chdir("watch_dir");
for (i = 0; i < readdir_req.result; i++) {
name = buffer;
r = remove(name);
ASSERT(r == 0);
buffer += strlen(name) + 1;
}
uv_chdir("..");
r = remove("watch_dir");
ASSERT(r == 0 || uv_last_error(loop).code == UV_ENOENT);
}

static void create_dir(uv_loop_t* loop, const char* name) {
int r;
uv_fs_t req;
Expand Down Expand Up @@ -180,11 +160,14 @@ static void timer_cb_touch(uv_timer_t* timer, int status) {
}

TEST_IMPL(fs_event_watch_dir) {
uv_fs_t fs_req;
uv_loop_t* loop = uv_default_loop();
int r;

/* Setup */
cleanup_watch_dir();
uv_fs_unlink(loop, &fs_req, "watch_dir/file1", NULL);
uv_fs_unlink(loop, &fs_req, "watch_dir/file2", NULL);
uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);
create_dir(loop, "watch_dir");

r = uv_fs_event_init(loop, &fs_event, "watch_dir", fs_event_cb_dir, 0);
Expand All @@ -201,15 +184,22 @@ TEST_IMPL(fs_event_watch_dir) {
ASSERT(close_cb_called == 2);

/* Cleanup */
cleanup_watch_dir();
r = uv_fs_unlink(loop, &fs_req, "watch_dir/file1", NULL);
r = uv_fs_unlink(loop, &fs_req, "watch_dir/file2", NULL);
r = uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);

return 0;
}

TEST_IMPL(fs_event_watch_file) {
uv_fs_t fs_req;
uv_loop_t* loop = uv_default_loop();
int r;

/* Setup */
uv_fs_unlink(loop, &fs_req, "watch_dir/file1", NULL);
uv_fs_unlink(loop, &fs_req, "watch_dir/file2", NULL);
uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);
create_dir(loop, "watch_dir");
create_file(loop, "watch_dir/file1");
create_file(loop, "watch_dir/file2");
Expand All @@ -228,7 +218,10 @@ TEST_IMPL(fs_event_watch_file) {
ASSERT(close_cb_called == 2);

/* Cleanup */
cleanup_watch_dir();
r = uv_fs_unlink(loop, &fs_req, "watch_dir/file1", NULL);
r = uv_fs_unlink(loop, &fs_req, "watch_dir/file2", NULL);
r = uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);

return 0;
}

Expand Down Expand Up @@ -271,11 +264,13 @@ TEST_IMPL(fs_event_watch_file_current_dir) {


TEST_IMPL(fs_event_no_callback_on_close) {
uv_fs_t fs_req;
uv_loop_t* loop = uv_default_loop();
int r;

/* Setup */
cleanup_watch_dir();
uv_fs_unlink(loop, &fs_req, "watch_dir/file1", NULL);
uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);
create_dir(loop, "watch_dir");
create_file(loop, "watch_dir/file1");

Expand All @@ -294,7 +289,8 @@ TEST_IMPL(fs_event_no_callback_on_close) {
ASSERT(close_cb_called == 1);

/* Cleanup */
cleanup_watch_dir();
r = uv_fs_unlink(loop, &fs_req, "watch_dir/file1", NULL);
r = uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);

return 0;
}
Expand Down Expand Up @@ -342,12 +338,11 @@ TEST_IMPL(fs_event_immediate_close) {

TEST_IMPL(fs_event_close_with_pending_event) {
uv_loop_t* loop;
uv_fs_t fs_req;
int r;

loop = uv_default_loop();

cleanup_watch_dir();

create_dir(loop, "watch_dir");
create_file(loop, "watch_dir/file");

Expand All @@ -364,7 +359,10 @@ TEST_IMPL(fs_event_close_with_pending_event) {
ASSERT(close_cb_called == 1);

/* Clean up */
cleanup_watch_dir();
r = uv_fs_unlink(loop, &fs_req, "watch_dir/file", NULL);
ASSERT(r == 0);
r = uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);
ASSERT(r == 0);

return 0;
}
Expand Down Expand Up @@ -397,12 +395,11 @@ static void fs_event_cb_close(uv_fs_event_t* handle, const char* filename,

TEST_IMPL(fs_event_close_in_callback) {
uv_loop_t* loop;
uv_fs_t fs_req;
int r;

loop = uv_default_loop();

cleanup_watch_dir();

create_dir(loop, "watch_dir");
create_file(loop, "watch_dir/file1");
create_file(loop, "watch_dir/file2");
Expand All @@ -426,7 +423,18 @@ TEST_IMPL(fs_event_close_in_callback) {
ASSERT(fs_event_cb_called == 3);

/* Clean up */
cleanup_watch_dir();
r = uv_fs_unlink(loop, &fs_req, "watch_dir/file1", NULL);
ASSERT(r == 0);
r = uv_fs_unlink(loop, &fs_req, "watch_dir/file2", NULL);
ASSERT(r == 0);
r = uv_fs_unlink(loop, &fs_req, "watch_dir/file3", NULL);
ASSERT(r == 0);
r = uv_fs_unlink(loop, &fs_req, "watch_dir/file4", NULL);
ASSERT(r == 0);
r = uv_fs_unlink(loop, &fs_req, "watch_dir/file5", NULL);
ASSERT(r == 0);
r = uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);
ASSERT(r == 0);

return 0;
}
Expand Down

0 comments on commit e9b17bc

Please sign in to comment.