Skip to content

Commit 1a70a86

Browse files
mkrufkykkoopa
authored andcommitted
test/*/asyncprogressqueueworker*: kill sleeps & rename a to doProgress
As described in #703 , these varying sleep tests for the `AsyncProgressQueueWorker` were created purely for the sake of the original pull request. These tests are somewhat redundant now as a result of the following commit: a5db7f0 - AsyncProgressQueueWorker: override workcomplete to ensure WorkProgress gets called So now we can remove any remnants of `Sleep` from the cpp addon, and go back to a single js test for the basic `AsyncProgressQueueWorker` without any forced sleeps. This also serves as a better coding example for the `AsyncProgressQueueWorker` class template. ...and while we're here, rename the addon entry point `a` to `doProgress`
1 parent 3f538ba commit 1a70a86

4 files changed

Lines changed: 8 additions & 64 deletions

File tree

test/cpp/asyncprogressqueueworker.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
* MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
77
********************************************************************/
88

9-
#ifndef _WIN32
10-
#include <unistd.h>
11-
#define Sleep(x) usleep((x)*1000)
12-
#endif
139
#include <nan.h>
1410

1511
using namespace Nan; // NOLINT(build/namespaces)
@@ -19,10 +15,9 @@ class ProgressQueueWorker : public AsyncProgressQueueWorker<char> {
1915
ProgressQueueWorker(
2016
Callback *callback
2117
, Callback *progress
22-
, int milliseconds
2318
, int iters)
2419
: AsyncProgressQueueWorker(callback), progress(progress)
25-
, milliseconds(milliseconds), iters(iters) {}
20+
, iters(iters) {}
2621

2722
~ProgressQueueWorker() {
2823
delete progress;
@@ -31,7 +26,6 @@ class ProgressQueueWorker : public AsyncProgressQueueWorker<char> {
3126
void Execute (const AsyncProgressQueueWorker::ExecutionProgress& progress) {
3227
for (int i = 0; i < iters; ++i) {
3328
progress.Send(reinterpret_cast<const char*>(&i), sizeof(int));
34-
Sleep(milliseconds);
3529
}
3630
}
3731

@@ -46,23 +40,21 @@ class ProgressQueueWorker : public AsyncProgressQueueWorker<char> {
4640

4741
private:
4842
Callback *progress;
49-
int milliseconds;
5043
int iters;
5144
};
5245

5346
NAN_METHOD(DoProgress) {
54-
Callback *progress = new Callback(info[2].As<v8::Function>());
55-
Callback *callback = new Callback(info[3].As<v8::Function>());
47+
Callback *progress = new Callback(info[1].As<v8::Function>());
48+
Callback *callback = new Callback(info[2].As<v8::Function>());
5649
AsyncQueueWorker(new ProgressQueueWorker(
5750
callback
5851
, progress
59-
, To<uint32_t>(info[0]).FromJust()
60-
, To<uint32_t>(info[1]).FromJust()));
52+
, To<uint32_t>(info[0]).FromJust()));
6153
}
6254

6355
NAN_MODULE_INIT(Init) {
6456
Set(target
65-
, New<v8::String>("a").ToLocalChecked()
57+
, New<v8::String>("doProgress").ToLocalChecked()
6658
, New<v8::FunctionTemplate>(DoProgress)->GetFunction());
6759
}
6860

test/js/asyncprogressqueueworker-0ms-test.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

test/js/asyncprogressqueueworker-1ms-test.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

test/js/asyncprogressqueueworker-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ const test = require('tap').test
1111
, bindings = require('bindings')({ module_root: testRoot, bindings: 'asyncprogressqueueworker' });
1212

1313
test('asyncprogressqueueworker', function (t) {
14-
// test with 100 ms sleep
15-
var worker = bindings.a
14+
// test with no sleep
15+
var worker = bindings.doProgress
1616
, progressed = 0
17-
worker(100, 5, function(i) {
17+
worker(5, function(i) {
1818
t.ok(i === progressed, 'got the progress updates #' + i);
1919
progressed++;
2020
}, function () {

0 commit comments

Comments
 (0)