From 6c77bd83f5913b9795730766fe939170fa1dd361 Mon Sep 17 00:00:00 2001 From: Nathan Whitaker Date: Tue, 21 Jan 2025 13:29:38 -0800 Subject: [PATCH] simplify uv test to make it not flaky --- tests/napi/src/uv.rs | 16 +++++++--------- tests/napi/uv_test.js | 3 +-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/tests/napi/src/uv.rs b/tests/napi/src/uv.rs index 45ca114adc..f664e09620 100644 --- a/tests/napi/src/uv.rs +++ b/tests/napi/src/uv.rs @@ -137,7 +137,7 @@ unsafe extern "C" fn callback(handle: *mut uv_async_t) { &mut result, )); uv_mutex_unlock((*async_).mutex); - if value == 5 { + if value == 1 { uv_close(handle.cast(), Some(close_cb)); } } @@ -166,7 +166,6 @@ extern "C" fn test_uv_async( let uv_async = uv_async.cast::(); let mut js_cb = null_mut(); assert_napi_ok!(napi_create_reference(env, args[0], 1, &mut js_cb)); - // let mut tsfn = null_mut(); let data = new_raw(Async { env, @@ -181,14 +180,13 @@ extern "C" fn test_uv_async( let uv_async = UvAsyncPtr(uv_async); std::thread::spawn({ move || { + std::thread::sleep(Duration::from_millis(50)); let data = (*uv_async.0).data as *mut Async; - for _ in 0..5 { - uv_mutex_lock((*data).mutex); - (*data).value += 1; - uv_mutex_unlock((*data).mutex); - std::thread::sleep(Duration::from_millis(10)); - uv_async_send(uv_async); - } + uv_mutex_lock((*data).mutex); + (*data).value += 1; + uv_mutex_unlock((*data).mutex); + std::thread::sleep(Duration::from_millis(10)); + uv_async_send(uv_async); } }); } diff --git a/tests/napi/uv_test.js b/tests/napi/uv_test.js index f0ff613f31..66f5564cb4 100644 --- a/tests/napi/uv_test.js +++ b/tests/napi/uv_test.js @@ -6,13 +6,12 @@ const uv = loadTestLibrary(); Deno.test({ name: "napi uv async", - ignore: true, fn: async () => { let called = false; await new Promise((resolve) => { uv.test_uv_async((value) => { called = true; - if (value === 5) { + if (value === 1) { resolve(); } });