From 223e526f27910c69672a7690ef400975fd6fe1bf Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 6 Apr 2022 13:40:51 +0200 Subject: [PATCH] test: fix flaky file watcher test (#3591) FSEvents on macOS sometimes sends one change event, sometimes two. Make the test more lenient. Fixes #3589. --- test/test-fs-event.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/test/test-fs-event.c b/test/test-fs-event.c index cbe63190..0e17e7df 100644 --- a/test/test-fs-event.c +++ b/test/test-fs-event.c @@ -334,19 +334,8 @@ static void fs_event_cb_file(uv_fs_event_t* handle, const char* filename, uv_close((uv_handle_t*)handle, close_cb); } -static void timer_cb_close_handle(uv_timer_t* timer) { - uv_handle_t* handle; - - ASSERT_NOT_NULL(timer); - handle = timer->data; - - uv_close((uv_handle_t*)timer, NULL); - uv_close((uv_handle_t*)handle, close_cb); -} - static void fs_event_cb_file_current_dir(uv_fs_event_t* handle, const char* filename, int events, int status) { - ASSERT(fs_event_cb_called == 0); ++fs_event_cb_called; ASSERT(handle == &fs_event); @@ -358,13 +347,7 @@ static void fs_event_cb_file_current_dir(uv_fs_event_t* handle, ASSERT(filename == NULL || strcmp(filename, "watch_file") == 0); #endif - /* Regression test for SunOS: touch should generate just one event. */ - { - static uv_timer_t timer; - uv_timer_init(handle->loop, &timer); - timer.data = handle; - uv_timer_start(&timer, timer_cb_close_handle, 250, 0); - } + uv_close((uv_handle_t*)handle, close_cb); } static void timer_cb_file(uv_timer_t* handle) { @@ -738,7 +721,8 @@ TEST_IMPL(fs_event_watch_file_current_dir) { uv_run(loop, UV_RUN_DEFAULT); ASSERT(timer_cb_touch_called == 1); - ASSERT(fs_event_cb_called == 1); + /* FSEvents on macOS sometimes sends one change event, sometimes two. */ + ASSERT_NE(0, fs_event_cb_called); ASSERT(close_cb_called == 1); /* Cleanup */