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: improve zlib tests #55716

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

anonrig
Copy link
Member

@anonrig anonrig commented Nov 4, 2024

Remove several unnecessary zlib tests, and use node:test as much as we can. This also avoids calling require('../common') functionality as much as we can.

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test Issues and PRs related to the tests. labels Nov 4, 2024
@avivkeller avivkeller added the zlib Issues and PRs related to the zlib subsystem. label Nov 4, 2024
Copy link

codecov bot commented Nov 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.40%. Comparing base (5d4fee8) to head (c1b6cb1).
Report is 101 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #55716      +/-   ##
==========================================
- Coverage   88.42%   88.40%   -0.02%     
==========================================
  Files         654      654              
  Lines      187662   187763     +101     
  Branches    36118    36127       +9     
==========================================
+ Hits       165945   165999      +54     
- Misses      14955    15006      +51     
+ Partials     6762     6758       -4     

see 80 files with indirect coverage changes

@anonrig anonrig force-pushed the yagiz/improve-zlib-tests branch 2 times, most recently from 8b49cae to e337280 Compare November 4, 2024 15:44
Copy link
Member

@lpinca lpinca left a comment

Choose a reason for hiding this comment

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

I'm fine with removing redundant tests but I'm -1 on using node:test as much as we can as per #54796 and #55110 (review). In my opinion this is not an improvement, but added complexity and spurious code executed as part of the test, which could also affect the reliability of the test itself.

@anonrig anonrig added the tsc-agenda Issues and PRs to discuss during the meetings of the TSC. label Nov 5, 2024
Comment on lines +59 to +68
const { promise, resolve } = Promise.withResolvers();
zlib.deflate(inputString, (err, buffer) => {
assert.ifError(err);
zlib.inflate(buffer, (err, inflated) => {
assert.ifError(err);
assert.strictEqual(inflated.toString(), inputString);
resolve();
});
});
await promise;
Copy link
Contributor

Choose a reason for hiding this comment

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

I love how Promise.withResolvers() helps making callback tests relatively concise, but I don't see how this is better than using common.mustSucceed():

Suggested change
const { promise, resolve } = Promise.withResolvers();
zlib.deflate(inputString, (err, buffer) => {
assert.ifError(err);
zlib.inflate(buffer, (err, inflated) => {
assert.ifError(err);
assert.strictEqual(inflated.toString(), inputString);
resolve();
});
});
await promise;
zlib.deflate(inputString, common.mustSucceed((buffer) => {
zlib.inflate(buffer, common.mustSucceed((inflated) => {
assert.strictEqual(inflated.toString(), inputString);
}));
}));

Is there a reason why we should avoid relying on common utilities?

Copy link
Member Author

Choose a reason for hiding this comment

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

common.mustSucceed() depends on process.on('exit') hook, whereas Promise.withResolvers() doesn't.

Comment on lines 162 to 164
out.on('end', resolve);

await promise;
Copy link
Member

Choose a reason for hiding this comment

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

can't we await once(out, 'end') ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, definitely! Nice catch. Thanks @targos

Copy link
Member

@lpinca lpinca Nov 8, 2024

Choose a reason for hiding this comment

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

This means replacing a Node.js specific API (common.mustCall()) with another Node.js specific API (events.once()). What's the point?

Copy link
Member Author

Choose a reason for hiding this comment

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

common.mustCall() depends on process.on('exit') where we definitely don't need to wait for the process to exit to check the state for this current implementation.

Copy link
Member

Choose a reason for hiding this comment

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

Ok but I don't see how it is an improvement. It doesn't change anything for the sake of the test.

@anonrig anonrig force-pushed the yagiz/improve-zlib-tests branch from e337280 to c1b6cb1 Compare November 8, 2024 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci PRs that need a full CI run. test Issues and PRs related to the tests. tsc-agenda Issues and PRs to discuss during the meetings of the TSC. zlib Issues and PRs related to the zlib subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants