Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: use uv_sleep() where possible #45124

Merged
merged 1 commit into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions test/addons/async-hello-world/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
#include <v8.h>
#include <uv.h>

#if defined _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif


struct async_req {
uv_work_t req;
int input;
Expand All @@ -21,11 +14,7 @@ struct async_req {
void DoAsync(uv_work_t* r) {
async_req* req = reinterpret_cast<async_req*>(r->data);
// Simulate CPU intensive process...
#if defined _WIN32
Sleep(1000);
#else
sleep(1);
#endif
uv_sleep(1000);
req->output = req->input * 2;
}

Expand Down
19 changes: 3 additions & 16 deletions test/node-api/test_async/test_async.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
#include <assert.h>
#include <stdio.h>
#include <node_api.h>
#include <uv.h>
#include "../../js-native-api/common.h"

#if defined _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif

// this needs to be greater than the thread pool size
#define MAX_CANCEL_THREADS 6

Expand All @@ -23,11 +18,7 @@ static carrier the_carrier;
static carrier async_carrier[MAX_CANCEL_THREADS];

static void Execute(napi_env env, void* data) {
#if defined _WIN32
Sleep(1000);
#else
sleep(1);
#endif
uv_sleep(1000);
carrier* c = (carrier*)(data);

assert(c == &the_carrier);
Expand Down Expand Up @@ -130,11 +121,7 @@ static void CancelComplete(napi_env env, napi_status status, void* data) {
}

static void CancelExecute(napi_env env, void* data) {
#if defined _WIN32
Sleep(1000);
#else
sleep(1);
#endif
uv_sleep(1000);
}

static napi_value TestCancel(napi_env env, napi_callback_info info) {
Expand Down