Skip to content

Commit

Permalink
test: use uv_sleep() where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
santigimeno committed Oct 25, 2022
1 parent bb7650b commit 131cdeb
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 131cdeb

Please sign in to comment.