Skip to content

Commit cfbf0b2

Browse files
vuanhphungIsaac
andcommitted
Strengthen CloudFetch retention regression coverage
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com> Co-authored-by: Isaac <no-reply@databricks.com>
1 parent 4b276e0 commit cfbf0b2

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

‎lib/result/CloudFetchResultHandler.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ export default class CloudFetchResultHandler implements IResultsProvider<ArrowBa
155155
if (!(body instanceof Readable)) {
156156
return response.buffer();
157157
}
158+
// node-fetch installs readers synchronously; their error listener also retains the settled body.
159+
// Remove only those readers, keeping the constructor's error handler for late stream errors.
158160
const events = ['data', 'end', 'error'];
159161
const existing = events.map((event) => body.listeners(event));
160162
const result = response.buffer();

‎tests/unit/result/CloudFetchResultHandler.test.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { expect, AssertionError } from 'chai';
22
import sinon, { SinonStub } from 'sinon';
33
import { execFileSync } from 'child_process';
44
import http from 'http';
5+
import path from 'path';
56
import { PassThrough } from 'stream';
67
import { AddressInfo } from 'net';
78
import Int64 from 'node-int64';
@@ -812,11 +813,13 @@ describe('CloudFetchResultHandler', () => {
812813

813814
it('handles late body errors without application error handlers or unhandled rejections', function () {
814815
this.timeout(15000);
816+
const repoRoot = path.resolve(__dirname, '../../..');
817+
const handlerPath = path.join(repoRoot, 'lib/result/CloudFetchResultHandler');
815818
const script = `
816819
const assert = require('assert').strict;
817820
const { PassThrough } = require('stream');
818821
const { Response } = require('node-fetch');
819-
const Handler = require('./lib/result/CloudFetchResultHandler').default;
822+
const Handler = require(${JSON.stringify(handlerPath)}).default;
820823
(async () => {
821824
const body = new PassThrough();
822825
const response = new Response(body);
@@ -839,8 +842,8 @@ describe('CloudFetchResultHandler', () => {
839842
`;
840843
const output = execFileSync(
841844
process.execPath,
842-
['--unhandled-rejections=strict', '--require', 'ts-node/register', '-e', script],
843-
{ cwd: process.cwd(), encoding: 'utf8', timeout: 10000, stdio: 'pipe' },
845+
['--unhandled-rejections=strict', '--require', require.resolve('ts-node/register'), '-e', script],
846+
{ cwd: repoRoot, encoding: 'utf8', timeout: 10000, stdio: 'pipe' },
844847
);
845848
expect(output).to.eq('late body error handled\n');
846849
});
@@ -936,6 +939,7 @@ describe('CloudFetchResultHandler', () => {
936939
expect(buffer.firstCall.thisValue.body).to.have.property('pipe').that.is.a('function');
937940
expect(buffer.firstCall.thisValue.body.listenerCount('data')).to.eq(0);
938941
expect(buffer.firstCall.thisValue.body.listenerCount('end')).to.eq(0);
942+
expect(buffer.firstCall.thisValue.body.listenerCount('error')).to.eq(1);
939943
const downloaded = await buffer.firstCall.returnValue;
940944
expect(downloaded).to.deep.eq(body);
941945
expect(downloaded.length).to.be.lt(Buffer.poolSize >>> 1);

0 commit comments

Comments
 (0)