Skip to content
Closed
Changes from 1 commit
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
12 changes: 3 additions & 9 deletions test/parallel/test-timers-clearImmediate.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');

const N = 3;
let count = 0;
function next() {
const immediate = setImmediate(function() {
const immediate = setImmediate(common.mustCall(() => {
clearImmediate(immediate);
++count;
});
}, 3));
Copy link
Contributor

@mscdex mscdex Apr 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just use N here instead. I think we just need common.mustCall() without a second argument when the loop below is kept.

}
for (let i = 0; i < N; ++i)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this loop is still needed?

next();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this test even do anything without this loop?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the below code work? It doesn't complain when I run test.

'use strict';
const common = require('../common');
const assert = require('assert');

const N = 3;
let count = 0;
function next() {
  const immediate = setImmediate(common.mustCall(() => {
    clearImmediate(immediate);
    ++count;
  }));
}

for(let i = 0; i < N; i++) {
  next();
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it doesn't complain, that means the test is passing (or possibly not even doing anything). I think you should:

  1. Put the for loop back.
  2. Remove the count variable.
  3. Drop the second argument to common.mustCall() as @mscdex said.


process.on('exit', () => {
assert.strictEqual(count, N, `Expected ${N} immediate callback executions`);
});