Skip to content

Commit

Permalink
add close after error zlib test
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Aug 22, 2024
1 parent 7464c56 commit ad5bd1a
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/workerd/api/node/tests/zlib-nodejs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,30 @@ export const zlibDestroyTest = {
},
};

// Tests are taken from:
// https://github.com/nodejs/node/blob/561bc87c7607208f0d3db6dcd9231efeb48cfe2f/test/parallel/test-zlib-close-after-error.js
export const closeAfterError = {
async test() {
const decompress = zlib.createGunzip(15);
const { promise, resolve } = Promise.withResolvers();
let errorHasBeenCalled = false;

decompress.on('error', () => {
errorHasBeenCalled = true;
strictEqual(decompress._closed, true);
decompress.close();
});

strictEqual(decompress._closed, false);
decompress.write('something invalid');
decompress.on('close', resolve);

await promise;

assert(errorHasBeenCalled, 'Error handler should have been called');
},
};

// Node.js tests relevant to zlib
//
// - [ ] test-zlib-brotli-16GB.js
Expand Down Expand Up @@ -692,7 +716,7 @@ export const zlibDestroyTest = {
// - [ ] test-zlib-from-gzip.js
// - [ ] test-zlib-object-write.js
// - [ ] test-zlib-write-after-flush.js
// - [ ] test-zlib-close-after-error.js
// - [x] test-zlib-close-after-error.js
// - [ ] test-zlib-dictionary-fail.js
// - [ ] test-zlib-from-gzip-with-trailing-garbage.js
// - [ ] test-zlib-params.js
Expand Down

0 comments on commit ad5bd1a

Please sign in to comment.