k6 icon indicating copy to clipboard operation
k6 copied to clipboard

Add ReadableStream support to k6

Open joanlopez opened this issue 1 year ago • 2 comments

What?

It adds support for ReadableStream from Streams API through experimental k6/experimental/streams module.

Why?

This is a prerequisite to unlock the development of other features in k6. It is also a nice-to-have feature for k6 users in general, that may want to use ReadableStream on their own.

Note for the reviewer

You can find the rationale behind some technical decisions (around goja, promises, etc) present on this changeset, in this Google Doc that I used to write some personal notes, as takeaways during the development process.

On top of that, @oleiade and I decided to keep the code comments for each step of those operations defined in the spec because it makes it easier to:

  • correlate the code and the spec.
  • identify bugs or non-compliant behaviors.
  • identify patterns that are repeated over the spec, and its correspondence in Go/goja.

So, although I know these could be arguable for some people, I'd personally push to keep them as long as I need to maintain and take care of this code.

Checklist

  • [X] I have performed a self-review of my code.
  • [X] I have added tests for my changes.
  • [X] I have run linter locally (make lint) and all checks pass.
  • [X] I have run tests locally (make tests) and all tests pass.
  • [X] I have commented on my code, particularly in hard-to-understand areas.

Related PR(s)/Issue(s)

Closes #3659 Contributes to #2978

joanlopez avatar Apr 19 '24 13:04 joanlopez

Codecov Report

Attention: Patch coverage is 0.28249% with 706 lines in your changes are missing coverage. Please review.

Project coverage is 70.79%. Comparing base (f38ac59) to head (598ac70).

:exclamation: Current head 598ac70 differs from pull request most recent head 89302f2. Consider uploading reports for the commit 89302f2 to get more accurate results

Files Patch % Lines
...odules/k6/experimental/streams/readable_streams.go 0.00% 208 Missing :warning:
...ntal/streams/readable_stream_default_controller.go 0.00% 134 Missing :warning:
js/modules/k6/experimental/streams/module.go 0.84% 117 Missing :warning:
...rimental/streams/readable_stream_default_reader.go 0.00% 63 Missing :warning:
.../k6/experimental/streams/readable_stream_reader.go 0.00% 59 Missing :warning:
js/modules/k6/experimental/streams/goja.go 0.00% 44 Missing :warning:
js/modules/k6/experimental/streams/queue.go 0.00% 25 Missing :warning:
js/modules/k6/experimental/streams/errors.go 0.00% 24 Missing :warning:
...dules/k6/experimental/streams/underlying_source.go 0.00% 17 Missing :warning:
js/modules/k6/experimental/streams/errors_gen.go 0.00% 11 Missing :warning:
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3696      +/-   ##
==========================================
- Coverage   73.29%   70.79%   -2.51%     
==========================================
  Files         278      287       +9     
  Lines       20456    21159     +703     
==========================================
- Hits        14994    14979      -15     
- Misses       4505     5217     +712     
- Partials      957      963       +6     
Flag Coverage Δ
ubuntu 70.79% <0.28%> (-2.44%) :arrow_down:
windows ?

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Apr 19 '24 14:04 codecov-commenter

Hey @mstoykov (cc/ @oleiade),

I have pushed a few more commits with some changes that go in the line of what has been discussed here.

Note that the approach is specific for streams, thus not extensible, but I guess we can postpone the task of finding a way to make the WPTs setup available for other suites as a separate work.

I also took the opportunity to remove the support for console.log, as discussed here, in order to move that discussion outside the scope of this pull request, as it isn't strictly needed.

Please, let know what do you think about the new approach. Thanks! 🙇🏻

joanlopez avatar Apr 24 '24 10:04 joanlopez

Just please squash on merge :grimacing:

mstoykov avatar Apr 29 '24 08:04 mstoykov

👍🏻 😄 🦖

oleiade avatar Apr 29 '24 08:04 oleiade