From ad5bd1a2e3f47fd9a77fb6709d01ff16d89d35c4 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Thu, 22 Aug 2024 16:44:37 -0400 Subject: [PATCH] add close after error zlib test --- .../api/node/tests/zlib-nodejs-test.js | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/workerd/api/node/tests/zlib-nodejs-test.js b/src/workerd/api/node/tests/zlib-nodejs-test.js index 6af6a27990f..60eb48f03b7 100644 --- a/src/workerd/api/node/tests/zlib-nodejs-test.js +++ b/src/workerd/api/node/tests/zlib-nodejs-test.js @@ -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 @@ -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