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 <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
Reviewed-By: theanarkh <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Daeyeon Jeong <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
  • Loading branch information
santigimeno authored and RafaelGSS committed Nov 10, 2022
1 parent 243c141 commit f9bc40a
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 f9bc40a

Please sign in to comment.