Skip to content

Commit 4d49fc9

Browse files
committed
f
1 parent c98be93 commit 4d49fc9

File tree

3 files changed

+45
-35
lines changed

3 files changed

+45
-35
lines changed

src/HttpClient.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export class HttpClient extends EventEmitter {
252252
const internalStore = {
253253
requestId,
254254
requestStartTime: performance.now(),
255-
enableRequestTiming: !!options?.timing,
255+
enableRequestTiming: !!(options?.timing ?? true),
256256
} as InternalStore;
257257
return await asyncLocalStorage.run(internalStore, async () => {
258258
return await this.#requestInternal<T>(url, options);
@@ -275,8 +275,6 @@ export class HttpClient extends EventEmitter {
275275
debug('Request#%d dns lookup %sms, servername: %s, origin: %s',
276276
store.requestId, dnslookup, options.servername, options.origin);
277277
}
278-
console.log(options);
279-
handler.opaque = options.opaque;
280278
return dispatch(options, handler);
281279
};
282280
},
@@ -344,7 +342,6 @@ export class HttpClient extends EventEmitter {
344342
contentDownload: 0,
345343
};
346344
internalStore.requestTiming = timing;
347-
internalStore.enableRequestTiming = !!args.timing;
348345
const originalOpaque = args.opaque;
349346
const reqMeta = {
350347
requestId,

src/fetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export class FetchFactory {
150150
const internalStore = {
151151
requestId,
152152
requestStartTime: performance.now(),
153-
enableRequestTiming: !!init.timing,
153+
enableRequestTiming: !!(init.timing ?? true),
154154
requestTiming: timing,
155155
} as InternalStore;
156156
const reqMeta: RequestMeta = {

test/options.timing.test.ts

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,55 +17,68 @@ describe('options.timing.test.ts', () => {
1717
await close();
1818
});
1919

20-
it.only('should timing = true work', async () => {
21-
// _url = _url.replace('localhost', '127.0.0.1');
20+
it('should timing = true work', async () => {
21+
_url = _url.replace('localhost', '127.0.0.1');
2222
let response = await urllib.request(`${_url}?content-encoding=gzip`, {
2323
dataType: 'json',
2424
timing: true,
2525
});
2626
assert.equal(response.status, 200);
2727
let res = response.res as RawResponseWithMeta;
28-
console.log(res.timing);
29-
// assert(res.timing.waiting > 0);
30-
// assert(res.timing.dnslookup > 0);
31-
// assert(res.timing.queuing > 0);
32-
// assert(res.timing.connected > 0);
33-
// assert(res.timing.requestHeadersSent > 0);
34-
// assert(res.timing.requestSent > 0);
35-
// assert(res.timing.contentDownload > 0);
36-
// assert(res.timing.contentDownload > res.timing.waiting);
37-
// assert(res.timing.contentDownload <= res.rt);
38-
assert(res.socket.handledResponses === 1);
28+
// console.log(res.timing);
29+
assert(res.timing.waiting > 0);
30+
assert(res.timing.dnslookup > 0);
31+
assert(res.timing.queuing > 0);
32+
assert(res.timing.connected > 0);
33+
assert(res.timing.requestHeadersSent > 0);
34+
assert(res.timing.requestSent > 0);
35+
assert(res.timing.contentDownload > 0);
36+
assert(res.timing.contentDownload > res.timing.waiting);
37+
assert(res.timing.contentDownload <= res.rt);
38+
assert.equal(res.socket.handledRequests, 1);
39+
assert.equal(res.socket.handledResponses, 1);
3940

4041
// again connected should be zero
41-
await sleep(1000);
42+
await sleep(1);
4243

4344
response = await urllib.request(`${_url}?content-encoding=gzip`, {
4445
dataType: 'json',
4546
timing: true,
4647
});
47-
await sleep(1000);
48-
console.log(response);
4948
assert.equal(response.status, 200);
5049
res = response.res as RawResponseWithMeta;
51-
console.log(res.timing);
52-
// assert.equal(res.timing.waiting, 0);
53-
// assert(res.timing.dnslookup > 0);
54-
// assert(res.timing.queuing > 0);
55-
// assert.equal(res.timing.connected, 0);
56-
// assert(res.timing.requestHeadersSent > 0);
57-
// assert(res.timing.requestSent > 0);
58-
// assert(res.timing.contentDownload > 0);
59-
// assert(res.timing.contentDownload > res.timing.waiting);
60-
// assert(res.timing.contentDownload <= res.rt);
61-
// assert(res.socket.handledResponses === 2);
50+
// console.log(res.timing);
51+
assert(res.timing.waiting > 0);
52+
assert(res.timing.dnslookup > 0);
53+
assert(res.timing.queuing > 0);
54+
assert.equal(res.timing.connected, 0);
55+
assert(res.timing.requestHeadersSent > 0);
56+
assert(res.timing.requestSent > 0);
57+
assert(res.timing.contentDownload > 0);
58+
assert(res.timing.contentDownload > res.timing.waiting);
59+
assert(res.timing.contentDownload <= res.rt);
60+
assert.equal(res.socket.handledRequests, 2);
61+
assert.equal(res.socket.handledResponses, 2);
62+
63+
await sleep(1);
6264

6365
response = await urllib.request(`${_url}?content-encoding=gzip`, {
6466
dataType: 'json',
6567
timing: true,
6668
});
67-
await sleep(1000);
68-
console.log(response);
69+
res = response.res as RawResponseWithMeta;
70+
// console.log(res.timing);
71+
assert(res.timing.waiting > 0);
72+
assert(res.timing.dnslookup > 0);
73+
assert(res.timing.queuing > 0);
74+
assert.equal(res.timing.connected, 0);
75+
assert(res.timing.requestHeadersSent > 0);
76+
assert(res.timing.requestSent > 0);
77+
assert(res.timing.contentDownload > 0);
78+
assert(res.timing.contentDownload > res.timing.waiting);
79+
assert(res.timing.contentDownload <= res.rt);
80+
assert.equal(res.socket.handledRequests, 3);
81+
assert.equal(res.socket.handledResponses, 3);
6982
});
7083

7184
it('should timing = false work', async () => {
@@ -88,7 +101,7 @@ describe('options.timing.test.ts', () => {
88101
assert.equal(response.status, 200);
89102
const res = response.res as RawResponseWithMeta;
90103
// console.log(res.timing);
91-
assert.equal(res.timing.waiting, 0);
104+
assert(res.timing.waiting > 0);
92105
assert(res.timing.dnslookup > 0);
93106
assert(res.timing.contentDownload > 0);
94107
assert(res.rt > 0);

0 commit comments

Comments
 (0)