Skip to content

Commit bc01b5a

Browse files
committed
chore: formatting
1 parent a7b24bc commit bc01b5a

File tree

6 files changed

+42
-38
lines changed

6 files changed

+42
-38
lines changed

packages/fetch-http-handler/src/fetch-http-handler.spec.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -305,35 +305,33 @@ const globalFetch = global.fetch;
305305
it("should use per-request timeout over handler config timeout", async () => {
306306
const mockFetch = vi.fn(() => new Promise(() => {})); // never resolve
307307
(global as any).fetch = mockFetch;
308-
308+
309309
const fetchHttpHandler = new FetchHttpHandler({ requestTimeout: 5000 });
310-
310+
311311
const start = Date.now();
312-
await expect(
313-
fetchHttpHandler.handle({} as any, { requestTimeout: 50 })
314-
).rejects.toHaveProperty("name", "TimeoutError");
315-
312+
await expect(fetchHttpHandler.handle({} as any, { requestTimeout: 50 })).rejects.toHaveProperty(
313+
"name",
314+
"TimeoutError"
315+
);
316+
316317
const elapsed = Date.now() - start;
317318
expect(elapsed).toBeLessThan(100); // should timeout quickly
318319
});
319320

320321
it("should fall back to handler config timeout when per-request timeout not provided", async () => {
321322
const mockFetch = vi.fn(() => new Promise(() => {}));
322323
(global as any).fetch = mockFetch;
323-
324+
324325
const fetchHttpHandler = new FetchHttpHandler({ requestTimeout: 50 });
325-
326+
326327
const start = Date.now();
327-
await expect(
328-
fetchHttpHandler.handle({} as any, {})
329-
).rejects.toHaveProperty("name", "TimeoutError");
330-
328+
await expect(fetchHttpHandler.handle({} as any, {})).rejects.toHaveProperty("name", "TimeoutError");
329+
331330
const elapsed = Date.now() - start;
332331
expect(elapsed).toBeLessThan(100);
333332
});
334333
});
335334

336-
337335
it("will throw timeout error it timeout finishes before request", async () => {
338336
const mockFetch = vi.fn(() => {
339337
return new Promise(() => {});

packages/fetch-http-handler/src/fetch-http-handler.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ export class FetchHttpHandler implements HttpHandler<FetchHttpHandlerOptions> {
7373
// Do nothing. TLS and HTTP/2 connection pooling is handled by the browser.
7474
}
7575

76-
async handle(request: HttpRequest, { abortSignal, requestTimeout }: HttpHandlerOptions = {}): Promise<{ response: HttpResponse }> {
76+
async handle(
77+
request: HttpRequest,
78+
{ abortSignal, requestTimeout }: HttpHandlerOptions = {}
79+
): Promise<{ response: HttpResponse }> {
7780
if (!this.config) {
7881
this.config = await this.configProvider;
7982
}

packages/node-http-handler/src/node-http-handler.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,17 +262,17 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
262262
describe("per-request requestTimeout", () => {
263263
it("should use per-request timeout over handler config timeout", () => {
264264
const nodeHttpHandler = new NodeHttpHandler({ requestTimeout: 5000 });
265-
const mockHandle = vi.spyOn(nodeHttpHandler, 'handle');
265+
const mockHandle = vi.spyOn(nodeHttpHandler, "handle");
266266
const testTimeout = (handlerTimeout: number, requestTimeout?: number) => {
267267
const handler = new NodeHttpHandler({ requestTimeout: handlerTimeout });
268268
const options = requestTimeout !== undefined ? { requestTimeout } : {};
269269
const expectedTimeout = requestTimeout ?? handlerTimeout;
270270
return expectedTimeout;
271271
};
272-
272+
273273
// per-request timeout takes precedence
274274
expect(testTimeout(5000, 100)).toBe(100);
275-
275+
276276
// fallback to handler config
277277
expect(testTimeout(200, undefined)).toBe(200);
278278
expect(testTimeout(200)).toBe(200);
@@ -284,7 +284,7 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
284284
requestTimeout: 5000,
285285
httpAgent: new http.Agent(),
286286
httpsAgent: new https.Agent(),
287-
logger: console
287+
logger: console,
288288
};
289289

290290
const httpRequest = new HttpRequest({
@@ -294,13 +294,13 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
294294
path: "/",
295295
headers: {},
296296
});
297-
297+
298298
const options1 = { requestTimeout: 100 };
299299
const options2 = {};
300-
300+
301301
const effectiveTimeout1 = options1.requestTimeout ?? (nodeHttpHandler as any).config.requestTimeout;
302302
const effectiveTimeout2 = options2.requestTimeout ?? (nodeHttpHandler as any).config.requestTimeout;
303-
303+
304304
expect(effectiveTimeout1).toBe(100); // per-request timeout
305305
expect(effectiveTimeout2).toBe(5000); // handler config timeout
306306
});

packages/node-http-handler/src/node-http-handler.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
152152
this.config?.httpsAgent?.destroy();
153153
}
154154

155-
async handle(request: HttpRequest, { abortSignal, requestTimeout }: HttpHandlerOptions = {}): Promise<{ response: HttpResponse }> {
155+
async handle(
156+
request: HttpRequest,
157+
{ abortSignal, requestTimeout }: HttpHandlerOptions = {}
158+
): Promise<{ response: HttpResponse }> {
156159
if (!this.config) {
157160
this.config = await this.configProvider;
158161
}

packages/node-http-handler/src/node-http2-handler.spec.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -568,45 +568,42 @@ describe(NodeHttp2Handler.name, () => {
568568
describe("per-request requestTimeout", () => {
569569
it("should use per-request timeout over handler config timeout", async () => {
570570
const nodeH2Handler = new NodeHttp2Handler({ requestTimeout: 5000 });
571-
571+
572572
const mockH2Server = mockH2Servers[port1];
573573
mockH2Server.removeAllListeners("request");
574574
mockH2Server.on("request", () => {
575575
// don't respond - let it timeout
576576
});
577-
577+
578578
const mockRequest = new HttpRequest(getMockReqOptions());
579579

580580
const start = Date.now();
581-
await expect(
582-
nodeH2Handler.handle(mockRequest, { requestTimeout: 100 })
583-
).rejects.toHaveProperty("name", "TimeoutError");
584-
581+
await expect(nodeH2Handler.handle(mockRequest, { requestTimeout: 100 })).rejects.toHaveProperty(
582+
"name",
583+
"TimeoutError"
584+
);
585+
585586
const elapsed = Date.now() - start;
586587
expect(elapsed).toBeLessThan(200);
587588
});
588589

589590
it("should fall back to handler config timeout when per-request timeout not provided", async () => {
590591
const nodeH2Handler = new NodeHttp2Handler({ requestTimeout: 100 });
591-
592+
592593
const mockH2Server = mockH2Servers[port1];
593594
mockH2Server.removeAllListeners("request");
594-
mockH2Server.on("request", () => {
595-
});
596-
595+
mockH2Server.on("request", () => {});
596+
597597
const mockRequest = new HttpRequest(getMockReqOptions());
598598

599599
const start = Date.now();
600-
await expect(
601-
nodeH2Handler.handle(mockRequest, {})
602-
).rejects.toHaveProperty("name", "TimeoutError");
603-
600+
await expect(nodeH2Handler.handle(mockRequest, {})).rejects.toHaveProperty("name", "TimeoutError");
601+
604602
const elapsed = Date.now() - start;
605603
expect(elapsed).toBeLessThan(200);
606604
});
607605
});
608606

609-
610607
describe.each([
611608
["object provider", async () => ({ disableConcurrentStreams: true })],
612609
["static object", { disableConcurrentStreams: true }],

packages/node-http-handler/src/node-http2-handler.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ export class NodeHttp2Handler implements HttpHandler<NodeHttp2HandlerOptions> {
8787
this.connectionManager.destroy();
8888
}
8989

90-
async handle(request: HttpRequest, { abortSignal, requestTimeout }: HttpHandlerOptions = {}): Promise<{ response: HttpResponse }> {
90+
async handle(
91+
request: HttpRequest,
92+
{ abortSignal, requestTimeout }: HttpHandlerOptions = {}
93+
): Promise<{ response: HttpResponse }> {
9194
if (!this.config) {
9295
this.config = await this.configProvider;
9396
this.connectionManager.setDisableConcurrentStreams(this.config.disableConcurrentStreams || false);

0 commit comments

Comments
 (0)