GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: fix flaky async-hooks/test-zlib.zlib-binding.deflate · nodejs/node@c4fc1ff

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/async-hooks
    • test-zlib.zlib-binding.deflate.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/async-hooks/test-zlib.zlib-binding.deflate.js‎

Copy file name to clipboardExpand all lines: test/async-hooks/test-zlib.zlib-binding.deflate.js
+16-7Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,37 @@ assert.strictEqual(typeof hdl.uid, 'number');
2121
assert.strictEqual(typeof hdl.triggerAsyncId, 'number');
2222
checkInvocations(hdl, { init: 1 }, 'when created handle');
2323

24+
// Store all buffers together so that they do not get
25+
// garbage collected.
26+
const buffers = {
27+
writeResult: new Uint32Array(2),
28+
dictionary: new Uint8Array(0),
29+
inBuf: new Uint8Array([0x78]),
30+
outBuf: new Uint8Array(1)
31+
};
32+
2433
handle.init(
2534
constants.Z_DEFAULT_WINDOWBITS,
2635
constants.Z_MIN_LEVEL,
2736
constants.Z_DEFAULT_MEMLEVEL,
2837
constants.Z_DEFAULT_STRATEGY,
29-
new Uint32Array(2),
38+
buffers.writeResult,
3039
function processCallback() { this.cb(); },
31-
Buffer.from('')
40+
buffers.dictionary
3241
);
3342
checkInvocations(hdl, { init: 1 }, 'when initialized handle');
3443

35-
const inBuf = Buffer.from('x');
36-
const outBuf = Buffer.allocUnsafe(1);
37-
3844
let count = 2;
3945
handle.cb = common.mustCall(onwritten, 2);
40-
handle.write(true, inBuf, 0, 1, outBuf, 0, 1);
46+
handle.write(true, buffers.inBuf, 0, 1, buffers.outBuf, 0, 1);
4147
checkInvocations(hdl, { init: 1 }, 'when invoked write() on handle');
4248

4349
function onwritten() {
4450
if (--count) {
4551
// first write
4652
checkInvocations(hdl, { init: 1, before: 1 },
4753
'when wrote to handle the first time');
48-
handle.write(true, inBuf, 0, 1, outBuf, 0, 1);
54+
handle.write(true, buffers.inBuf, 0, 1, buffers.outBuf, 0, 1);
4955
} else {
5056
// second write
5157
checkInvocations(hdl, { init: 1, before: 2, after: 1 },
@@ -61,4 +67,7 @@ function onexit() {
6167
// TODO: destroy never called here even with large amounts of ticks
6268
// is that correct?
6369
checkInvocations(hdl, { init: 1, before: 2, after: 2 }, 'when process exits');
70+
71+
// Do something with `buffers` to keep them alive until here.
72+
buffers.buffers = buffers;
6473
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.