Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: adding mustCall in test-timers-clearImmediate.js #12598

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

const N = 3;
let count = 0;

function next() {
const immediate = setImmediate(function() {
clearImmediate(immediate);
++count;
});
const immediate = setImmediate(common.mustCall(() => clearImmediate(immediate)));
}
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`);
});
for(let i = 0; i < N; i++) {
next();
}