Skip to content

Commit

Permalink
test: use uv_sleep() where possible
Browse files Browse the repository at this point in the history
PR-URL: #45124
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: theanarkh <theratliter@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
  • Loading branch information
santigimeno authored and danielleadams committed Jan 3, 2023
1 parent 64b0495 commit 7b8380d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 28 deletions.
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

0 comments on commit 7b8380d

Please sign in to comment.