Skip to content

Commit 8b01dd3

Browse files
committed
fixing the tests
1 parent da4ede8 commit 8b01dd3

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

extensions/sql-database-projects/src/http/httpClientCore.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ export class HttpClientCore {
131131
}
132132

133133
await new Promise<void>((resolve, reject) => {
134-
const tmpFile = fs.createWriteStream("", { fd: destinationFd });
134+
// autoClose: false keeps fd ownership with the caller (who calls fs.closeSync in finally).
135+
// Without it, pipe's automatic end() would trigger auto-close of the fd,
136+
// causing the caller's fs.closeSync to throw EBADF.
137+
const tmpFile = fs.createWriteStream("", { fd: destinationFd, autoClose: false });
135138

136139
const cleanup = (err: NodeJS.ErrnoException) => {
137140
// Destroy both streams to avoid file-descriptor leaks and stalled pipes
@@ -148,9 +151,8 @@ export class HttpClientCore {
148151
tmpFile.on("error", cleanup);
149152

150153
// Resolve only after the WriteStream has fully flushed to disk.
151-
// Using pipe without { end: false } so that the WriteStream is
152-
// automatically ended when the response stream finishes, which
153-
// triggers the 'finish' event once all bytes have been written.
154+
// pipe automatically calls tmpFile.end() when the response stream finishes,
155+
// which triggers the 'finish' event once all bytes have been written.
154156
tmpFile.on("finish", resolve);
155157

156158
response.data.pipe(tmpFile);

extensions/sql-database-projects/test/httpClient.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ suite("HttpClient tests", () => {
468468

469469
// eslint-disable-next-line @typescript-eslint/no-explicit-any
470470
sandbox.stub(httpClient as any, "createProxyAgent").returns({
471-
isHttps: true,
472471
// eslint-disable-next-line @typescript-eslint/no-explicit-any
473472
agent: {} as any,
474473
});
@@ -493,16 +492,16 @@ suite("HttpClient tests", () => {
493492

494493
// eslint-disable-next-line @typescript-eslint/no-explicit-any
495494
sandbox.stub(httpClient as any, "createProxyAgent").returns({
496-
isHttps: false,
497495
// eslint-disable-next-line @typescript-eslint/no-explicit-any
498496
agent: {} as any,
499497
});
500498

501499
const result = httpClient["setupConfigAndProxyForRequest"](requestUrl, token);
502500

503501
expect(result.proxy).to.be.false;
504-
expect(result.httpAgent).to.exist;
505-
expect(result.httpsAgent).to.be.undefined;
502+
// HTTPS request URL → httpsAgent, regardless of proxy scheme
503+
expect(result.httpsAgent).to.exist;
504+
expect(result.httpAgent).to.be.undefined;
506505
});
507506

508507
test("should log when proxy is found", () => {
@@ -518,7 +517,6 @@ suite("HttpClient tests", () => {
518517

519518
// eslint-disable-next-line @typescript-eslint/no-explicit-any
520519
sandbox.stub(httpClient as any, "createProxyAgent").returns({
521-
isHttps: false,
522520
// eslint-disable-next-line @typescript-eslint/no-explicit-any
523521
agent: {} as any,
524522
});

0 commit comments

Comments
 (0)