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

Add support for Blob #74

Merged
merged 23 commits into from
Jul 3, 2024
Merged

Add support for Blob #74

merged 23 commits into from
Jul 3, 2024

Conversation

joanlopez
Copy link
Contributor

@joanlopez joanlopez commented Jun 18, 2024

What?

It adds support for Blob, as described in #35

Why?

In order to stabilize the API before considering the extension non-experimental.

Checklist

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

Related PR(s)/Issue(s)

Closes #35

@joanlopez joanlopez self-assigned this Jun 18, 2024
@joanlopez joanlopez requested a review from a team as a code owner June 18, 2024 15:45
websockets/blob.go Outdated Show resolved Hide resolved
websockets/blob.go Outdated Show resolved Hide resolved
websockets/websockets.go Outdated Show resolved Hide resolved
Copy link
Contributor

@olegbespalov olegbespalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No specific feedback from my side, what Mihails said + linter fixes sounds like to plan to address 👍

nit: There are few places where we just throw an error like common.Throw(rt, err), I'd suggest add some context by wrapping the error

Copy link
Contributor

@olegbespalov olegbespalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Please also update README.md since it contains some Blob references that become misleading after merging this 👍

websockets/blob.go Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
Copy link
Contributor

@olegbespalov olegbespalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

go.mod Outdated Show resolved Hide resolved
websockets/blob_test.go Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
websockets/blob.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@mstoykov mstoykov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in general but is missing the fairly important part of using Blob to send data.

So I will be requesting that as well on top of some nitpicks and the dependency updates :)

}

// toByteSlice converts a slice of numbers to a slice of bytes.
func toByteSlice(data interface{}) []byte {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open for suggestions, although none of the ones I've seen so far really convinces me. If you prefer any other, just tell me.

@joanlopez joanlopez requested a review from mstoykov July 1, 2024 21:40
@joanlopez
Copy link
Contributor Author

LGTM in general but is missing the fairly important part of using Blob to send data.

So I will be requesting that as well on top of some nitpicks and the dependency updates :)

Hey @mstoykov,

On top of nitpicks, I've added a bunch of changes:

  • Extended the support to construct new Blobs for all the types described in the spec (ArrayBuffers, TypedArrays, DataViews, Blobs, strings, or a mix of any of such elements)
  • Added support for the type attribute (now assigned from constructor options)
  • Added support for the missing methods: bytes(), slice() and stream().
  • Changed the return type of some of these methods to Promise, as described in the spec: arrayBuffer(), bytes() and text().
  • Added support to also use Blob for sending.

So, with all that, I think we're in a quite decent position (after your review), to ship this support, as I think it's quite compliant.
That said, I'd recommend you to take a look at all these changes by following the commit history in order, as it's probably easier to follow, specially considering that you already did a review. Just in case.

Thanks! 🙇🏻

@joanlopez joanlopez dismissed mstoykov’s stale review July 1, 2024 21:47

Re-review requested

Copy link
Collaborator

@mstoykov mstoykov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in general, but the isBlob part is actually blocking.

I will be glad to have more tests especially if we can get some suite working, but we can have this after we merge this.

websockets/blob.go Show resolved Hide resolved
websockets/helpers.go Outdated Show resolved Hide resolved
websockets/websockets.go Outdated Show resolved Hide resolved
@joanlopez joanlopez requested a review from mstoykov July 3, 2024 09:34
@joanlopez
Copy link
Contributor Author

LGTM in general, but the isBlob part is actually blocking.

Fixed, thanks to your suggestion! 🙇🏻

I will be glad to have more tests especially if we can get some suite working, but we can have this after we merge this.

To be honest, after my experience with Streams API, and considering that experience wasn't smooth for other extensions (see grafana/xk6-webcrypto#81), I'd prefer to wait until we either make this extension part of k6-core or we make k6 surface for extensions that want to test against WPTs more reusable.

In fact, arguably that could even be considered a requirement if we eventually support dynamic extension (more chances to keep extension isolated). Also, considering v1.0 guarantees, we can try to think about something reusable that isn't strictly part of k6 core surface/guarantees.

In any case, I'd prefer to move on and postpone that discussion. I can create an equivalent of grafana/xk6-webcrypto#81 for this extension, if you want.

All that said, as I mentioned here, I did code this implementation within the k6 code base locally, so we don't have checks in place for future chances, but technically this implementation is already partly compliant with WPTs. It's something.

@joanlopez joanlopez merged commit 75c13b2 into main Jul 3, 2024
10 checks passed
@joanlopez joanlopez deleted the blob-support branch July 3, 2024 10:46
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.

Support Blob
3 participants