Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tests with all Node frameworks, fix ReadableStream.cancel & remove URL ponyfill #1929

Merged
merged 25 commits into from
Jan 7, 2025

Conversation

ardatan
Copy link
Owner

@ardatan ardatan commented Dec 27, 2024

Improvements on tests

  • Run tests with all possible server implementation(Node frameworks; uWS, Express, Fastify, Koa, Hapi and vanilla node:http) and Deno
  • Enable Leak tests for all test cases again for all frameworks thanks to our more stable leak detector

Fixes on `node-fetch

  • Remove URL ponyfill implementation based on fast-url-parser and fast-querystring, because Node now uses Ada URL parser which is fast enough.

  • Fix ReadableStream[Symbol.asyncIterator] (realized when using Readable.from in hapi integration)

ReadableStream uses Readable so it uses Symbol.asyncIterator method of Readable but the returned iterator's .return method doesn't handle cancellation correctly. So we need to call readable.destroy(optionalError) manually to cancel the stream.

This allows ReadableStream to use implementations relying on AsyncIterable.cancel to handle cancellation like Readable.from

Previously the following was not handling cancellation;

const res = new ReadableStream({
  start(controller) {
    controller.enqueue('Hello');
    controller.enqueue('World');
  },
  cancel(reason) {
    console.log('cancelled', reason);
  }
});

const readable = Readable.from(res);

readable.destroy(new Error('MY REASON'));

// Should log 'cancelled MY REASON'

Copy link
Contributor

github-actions bot commented Dec 27, 2024

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@whatwg-node/fetch 0.10.2-alpha-20250107102124-95009f6a70fffe8ad13cd9c1dab959ef39fe781f npm ↗︎ unpkg ↗︎
@whatwg-node/node-fetch 0.7.6-alpha-20250107102124-95009f6a70fffe8ad13cd9c1dab959ef39fe781f npm ↗︎ unpkg ↗︎

Copy link
Contributor

github-actions bot commented Dec 27, 2024

@benchmarks/node-fetch results (consumeBody)

   ✓ active_handles.................: avg=140.395626 min=53      med=140     max=197      p(90)=160     p(95)=165    
     data_received..................: 21 MB  706 kB/s
     data_sent......................: 14 MB  453 kB/s
     http_req_blocked...............: avg=3.6µs      min=631ns   med=1.23µs  max=5.59ms   p(90)=2µs     p(95)=2.24µs 
     http_req_connecting............: avg=1.81µs     min=0s      med=0s      max=5.21ms   p(90)=0s      p(95)=0s     
     http_req_duration..............: avg=21.59ms    min=8.39ms  med=21.11ms max=963.23ms p(90)=27.29ms p(95)=29.16ms
       { expected_response:true }...: avg=21.59ms    min=8.39ms  med=21.11ms max=963.23ms p(90)=27.29ms p(95)=29.16ms
     http_req_failed................: 0.00%  ✓ 0           ✗ 138498
     http_req_receiving.............: avg=32.09µs    min=8.91µs  med=23.16µs max=14.04ms  p(90)=37.17µs p(95)=43.62µs
     http_req_sending...............: avg=10.95µs    min=3.18µs  med=6.02µs  max=6.29ms   p(90)=9.67µs  p(95)=13.25µs
     http_req_tls_handshaking.......: avg=0s         min=0s      med=0s      max=0s       p(90)=0s      p(95)=0s     
     http_req_waiting...............: avg=21.54ms    min=8.2ms   med=21.07ms max=963.18ms p(90)=27.25ms p(95)=29.09ms
     http_reqs......................: 138498 4616.168616/s
     iteration_duration.............: avg=43.28ms    min=21.87ms med=41.77ms max=990.46ms p(90)=48.4ms  p(95)=53.6ms 
     iterations.....................: 69232  2307.517694/s
     vus............................: 100    min=100       max=100 
     vus_max........................: 100    min=100       max=100 

Copy link
Contributor

github-actions bot commented Dec 27, 2024

@benchmarks/node-fetch results (noConsumeBody)

   ✓ active_handles.................: avg=140.907612 min=31      med=142     max=184     p(90)=158     p(95)=164    
     data_received..................: 22 MB  720 kB/s
     data_sent......................: 14 MB  466 kB/s
     http_req_blocked...............: avg=3.84µs     min=641ns   med=1.42µs  max=5.91ms  p(90)=2.05µs  p(95)=2.34µs 
     http_req_connecting............: avg=1.86µs     min=0s      med=0s      max=5.45ms  p(90)=0s      p(95)=0s     
     http_req_duration..............: avg=21.18ms    min=7.31ms  med=20.6ms  max=1.07s   p(90)=26.54ms p(95)=28.43ms
       { expected_response:true }...: avg=21.18ms    min=7.31ms  med=20.6ms  max=1.07s   p(90)=26.54ms p(95)=28.42ms
     http_req_failed................: 0.00%  ✓ 1           ✗ 141143
     http_req_receiving.............: avg=33.87µs    min=9.48µs  med=24.36µs max=15.91ms p(90)=39.36µs p(95)=46.77µs
     http_req_sending...............: avg=11.69µs    min=3.54µs  med=6.97µs  max=15.59ms p(90)=10.29µs p(95)=14.92µs
     http_req_tls_handshaking.......: avg=0s         min=0s      med=0s      max=0s      p(90)=0s      p(95)=0s     
     http_req_waiting...............: avg=21.13ms    min=7.21ms  med=20.56ms max=1.07s   p(90)=26.49ms p(95)=28.35ms
     http_reqs......................: 141144 4704.312631/s
     iteration_duration.............: avg=42.48ms    min=21.74ms med=41.04ms max=1.09s   p(90)=46.98ms p(95)=52.09ms
     iterations.....................: 70550  2351.423058/s
     vus............................: 100    min=100       max=100 
     vus_max........................: 100    min=100       max=100 

Copy link
Contributor

github-actions bot commented Dec 27, 2024

@benchmarks/server results (ponyfill)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 297392      ✗ 0     
     data_received..................: 29 MB   976 kB/s
     data_sent......................: 12 MB   397 kB/s
     http_req_blocked...............: avg=1.37µs   min=861ns    med=1.15µs   max=5.21ms   p(90)=1.81µs   p(95)=1.96µs  
     http_req_connecting............: avg=0ns      min=0s       med=0s       max=120.98µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=139.63µs min=93.79µs  med=135.37µs max=5.99ms   p(90)=157.28µs p(95)=164.24µs
       { expected_response:true }...: avg=139.63µs min=93.79µs  med=135.37µs max=5.99ms   p(90)=157.28µs p(95)=164.24µs
     http_req_failed................: 0.00%   ✓ 0           ✗ 148696
     http_req_receiving.............: avg=24.2µs   min=12.39µs  med=22.74µs  max=3.06ms   p(90)=29.91µs  p(95)=32.6µs  
     http_req_sending...............: avg=6.23µs   min=3.9µs    med=5.36µs   max=1.26ms   p(90)=8.01µs   p(95)=8.59µs  
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=109.2µs  min=68µs     med=104.53µs max=5.94ms   p(90)=123.48µs p(95)=129.07µs
     http_reqs......................: 148696  4956.348264/s
     iteration_duration.............: avg=197.27µs min=142.95µs med=192.15µs max=6.38ms   p(90)=217.31µs p(95)=226.25µs
     iterations.....................: 148696  4956.348264/s
     vus............................: 1       min=1         max=1   
     vus_max........................: 1       min=1         max=1   

Copy link
Contributor

github-actions bot commented Dec 27, 2024

@benchmarks/server results (undici)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 212362      ✗ 0     
     data_received..................: 21 MB   711 kB/s
     data_sent......................: 8.5 MB  283 kB/s
     http_req_blocked...............: avg=1.52µs   min=912ns    med=1.29µs   max=306.8µs  p(90)=2.02µs   p(95)=2.21µs  
     http_req_connecting............: avg=1ns      min=0s       med=0s       max=143.66µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=217.29µs min=155.9µs  med=204.62µs max=60.23ms  p(90)=230.54µs p(95)=240.53µs
       { expected_response:true }...: avg=217.29µs min=155.9µs  med=204.62µs max=60.23ms  p(90)=230.54µs p(95)=240.53µs
     http_req_failed................: 0.00%   ✓ 0           ✗ 106181
     http_req_receiving.............: avg=26.83µs  min=14.04µs  med=25.26µs  max=3.17ms   p(90)=32.45µs  p(95)=35.05µs 
     http_req_sending...............: avg=6.84µs   min=4.16µs   med=6.31µs   max=336.6µs  p(90)=8.56µs   p(95)=9.71µs  
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=183.61µs min=130.25µs med=171.41µs max=60.15ms  p(90)=194.3µs  p(95)=203.23µs
     http_reqs......................: 106181  3539.159058/s
     iteration_duration.............: avg=277.78µs min=199.9µs  med=263.92µs max=60.37ms  p(90)=293.75µs p(95)=306.38µs
     iterations.....................: 106181  3539.159058/s
     vus............................: 1       min=1         max=1   
     vus_max........................: 1       min=1         max=1   

Copy link
Contributor

github-actions bot commented Dec 27, 2024

@benchmarks/server results (native)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 200654      ✗ 0     
     data_received..................: 20 MB   672 kB/s
     data_sent......................: 8.0 MB  268 kB/s
     http_req_blocked...............: avg=1.42µs   min=852ns    med=1.2µs    max=269.63µs p(90)=1.91µs   p(95)=2.1µs   
     http_req_connecting............: avg=1ns      min=0s       med=0s       max=123.33µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=233.35µs min=175.27µs med=221.99µs max=7.69ms   p(90)=250.88µs p(95)=263.04µs
       { expected_response:true }...: avg=233.35µs min=175.27µs med=221.99µs max=7.69ms   p(90)=250.88µs p(95)=263.04µs
     http_req_failed................: 0.00%   ✓ 0           ✗ 100327
     http_req_receiving.............: avg=26.15µs  min=14.14µs  med=24.4µs   max=2.65ms   p(90)=31.69µs  p(95)=34.72µs 
     http_req_sending...............: avg=6.69µs   min=4.06µs   med=6.05µs   max=422.32µs p(90)=8.42µs   p(95)=9.4µs   
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=200.51µs min=148.94µs med=189.31µs max=7.64ms   p(90)=214.81µs p(95)=225.76µs
     http_reqs......................: 100327  3344.098284/s
     iteration_duration.............: avg=294.31µs min=220.72µs med=282.1µs  max=7.78ms   p(90)=314.9µs  p(95)=329.81µs
     iterations.....................: 100327  3344.098284/s
     vus............................: 1       min=1         max=1   
     vus_max........................: 1       min=1         max=1   

@ardatan ardatan marked this pull request as draft December 27, 2024 10:17
@ardatan ardatan force-pushed the all-tests branch 2 times, most recently from 92c95c8 to 23fb6bd Compare December 27, 2024 11:56
@ardatan ardatan changed the title Run tests with all Node frameworks & fix URL Run tests with all Node frameworks & some fixes on URL and ReadableStream.cancel Dec 27, 2024
@ardatan ardatan force-pushed the all-tests branch 3 times, most recently from 763fdcd to e60dc5d Compare December 27, 2024 12:13
@ardatan ardatan marked this pull request as ready for review December 27, 2024 12:13
@ardatan ardatan force-pushed the all-tests branch 9 times, most recently from d2f2cdc to 69a2b8e Compare December 27, 2024 13:19
@ardatan ardatan requested review from Urigo and n1ru4l December 27, 2024 13:41
@ardatan ardatan merged commit b88b85c into master Jan 7, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants