dgram: extract cluster lazy loading method to make it testable#38563
dgram: extract cluster lazy loading method to make it testable#38563aduh95 merged 1 commit intonodejs:masterfrom
Conversation
RaisinTen
left a comment
There was a problem hiding this comment.
Instead of using the raw cluster object, what do you think about using lazyLoadCluster()?
function lazyLoadCluster() {
return cluster ??= require('cluster');
}That way, the check for whether the module has been loaded is abstracted away and the original internal API too does not change.
Good idea. In this way the lazy load method can be tested. |
|
Fast-track has been requested by @jasnell. Please 👍 to approve. |
Trott
left a comment
There was a problem hiding this comment.
I don't think any of this touches a hot code path, but just to be extra cautious, I'll kick off a benchmark CI.
|
Totally unnecessary benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1017/ Results |
PR-URL: nodejs#38563 Refs: https://coverage.nodejs.org/coverage-26e318a321a872bc/lib/dgram.js.html#L202 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
|
Landed in 1b11398 |
PR-URL: #38563 Refs: https://coverage.nodejs.org/coverage-26e318a321a872bc/lib/dgram.js.html#L202 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
PR-URL: #38563 Refs: https://coverage.nodejs.org/coverage-26e318a321a872bc/lib/dgram.js.html#L202 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
PR-URL: #38563 Refs: https://coverage.nodejs.org/coverage-26e318a321a872bc/lib/dgram.js.html#L202 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
PR-URL: #38563 Refs: https://coverage.nodejs.org/coverage-26e318a321a872bc/lib/dgram.js.html#L202 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
PR-URL: #38563 Refs: https://coverage.nodejs.org/coverage-26e318a321a872bc/lib/dgram.js.html#L202 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
There is no need to ensureclusterloaded inbindServerHandlebecauseit's already loaded before calling it.
This PR makesclusteras an argument to remind developers thatclusterneeds to be loaded before calling this function.
Update:
The lazy load parts in
bindServerHandleis unreachable becauseclusterhas been loaded before calling it. Extract it to a seperated method to make the code testable.Refs:
https://coverage.nodejs.org/coverage-26e318a321a872bc/lib/dgram.js.html#L202