From 1ff84206613e17e4d2242b96e3b6be7288840043 Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Sun, 26 Jan 2020 11:46:29 +0100 Subject: [PATCH] test: fix fs_event_watch_dir_recursive flakiness MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This test sometimes times out on `macos` because not all the expected events are received: the create and delete events may coalesce. To avoid it, make sure not to start deleting the files until all the create events are received. Also, take into account in the test that a create event of the `subdir` directory can be detected even though we start watching for the events after its creation. PR-URL: https://github.com/libuv/libuv/pull/2648 Reviewed-By: Colin Ihrig Reviewed-By: Jameson Nash Reviewed-By: Saúl Ibarra Corretgé --- test/test-fs-event.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/test-fs-event.c b/test/test-fs-event.c index e694d258e..28a6a1ebb 100644 --- a/test/test-fs-event.c +++ b/test/test-fs-event.c @@ -285,6 +285,12 @@ static void fs_event_cb_dir_multi_file_in_subdir(uv_fs_event_t* handle, if (filename && strcmp(filename, file_prefix_in_subdir) == 0) return; #endif + /* It may happen that the "subdir" creation event is captured even though + * we started watching after its actual creation. + */ + if (strcmp(filename, "subdir") == 0) + return; + fs_multievent_cb_called++; ASSERT(handle == &fs_event); ASSERT(status == 0); @@ -300,11 +306,13 @@ static void fs_event_cb_dir_multi_file_in_subdir(uv_fs_event_t* handle, sizeof(file_prefix_in_subdir) - 1) == 0); #endif - if (fs_event_created + fs_event_removed == fs_event_file_count) { + if (fs_event_created == fs_event_file_count && + fs_multievent_cb_called == fs_event_created) { /* Once we've processed all create events, delete all files */ ASSERT(0 == uv_timer_start(&timer, fs_event_unlink_files_in_subdir, 1, 0)); } else if (fs_multievent_cb_called == 2 * fs_event_file_count) { /* Once we've processed all create and delete events, stop watching */ + ASSERT(fs_event_removed == fs_event_file_count); uv_close((uv_handle_t*) &timer, close_cb); uv_close((uv_handle_t*) handle, close_cb); }