Skip to content

Commit

Permalink
fs,macos: fix fs_event_watch_dir_recursive flakiness
Browse files Browse the repository at this point in the history
This test sometimes times out 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.
  • Loading branch information
santigimeno committed Jan 26, 2020
1 parent 3ac654c commit f1fdfaa
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion test/test-fs-event.c
Expand Up @@ -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);
Expand All @@ -293,18 +299,21 @@ static void fs_event_cb_dir_multi_file_in_subdir(uv_fs_event_t* handle,
ASSERT(strncmp(filename,
file_prefix_in_subdir,
sizeof(file_prefix_in_subdir) - 1) == 0);

#else
ASSERT(filename == NULL ||
strncmp(filename,
file_prefix_in_subdir,
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);
}
Expand Down

0 comments on commit f1fdfaa

Please sign in to comment.