Skip to content

Use ws WebSocket when options are provided #2968

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

Merged
merged 6 commits into from
Jan 29, 2025

Conversation

KyleBoyer
Copy link
Contributor

The current 3.7-dev implementation does not pass headers to the WebSocket when utilizing the globalThis.WebSocket. This causes issues when initially upgrading to this version of gremlin (or upgrading to Node 22 when the global WebSocket class was enabled by default). This PR ensures that we use the ws WebSocket implementation if ws specific options are passed along.

@KyleBoyer KyleBoyer changed the base branch from master to 3.7-dev January 10, 2025 05:42
@codecov-commenter
Copy link

codecov-commenter commented Jan 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.37%. Comparing base (9b46b67) to head (2746f79).
Report is 290 commits behind head on 3.7-dev.

Additional details and impacted files
@@              Coverage Diff              @@
##             3.7-dev    #2968      +/-   ##
=============================================
+ Coverage      76.14%   76.37%   +0.22%     
- Complexity     13152    13232      +80     
=============================================
  Files           1084     1061      -23     
  Lines          65160    61574    -3586     
  Branches        7285     7341      +56     
=============================================
- Hits           49616    47025    -2591     
+ Misses         12839    12030     -809     
+ Partials        2705     2519     -186     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kenhuuu
Copy link
Contributor

kenhuuu commented Jan 13, 2025

The only thing that might be a problem is that there may be a small set of users who will now use globalThis.WebSocket instead of ws since they didn't pass any options. This, however, is probably a very minor concern since the two should be behaviorally the same and underlying _ws isn't exposed.

Thanks for helping to make gremlin-javascript more compatible with later versions of Node.

VOTE +1

@KyleBoyer
Copy link
Contributor Author

@kenhuuu is this good to merge? 😁

@kenhuuu
Copy link
Contributor

kenhuuu commented Jan 22, 2025

Yes, it passed lazy consensus since you got my vote. However, I don't know JavaScript or gremlin-javascript that well so I'd like to keep it open a little while longer just to give an opportunity for another contributor to review it. If there is no other review done by this Friday the 24th, then I'll merge this and the other PR you opened.

return connection.open();
});
Promise.allSettled(allOptionTests).then(function () {
if (globalWebsocketCalls !== domUnsupportedOptions.length) {

Choose a reason for hiding this comment

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

@KyleBoyer Where does domUnsupportedOptions come from?

And in this test, wouldn't globalWebsocketCalls === 0?

Copy link
Contributor Author

@KyleBoyer KyleBoyer Jan 24, 2025

Choose a reason for hiding this comment

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

Ahh, that should be / was renamed towsSpecificOptions. I'll push that change shortly.

Correct, in this test the globalWebsocketCalls should be 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kmcginnes Changes pushed!

@kenhuuu
Copy link
Contributor

kenhuuu commented Jan 25, 2025

If there is no other review done by this Friday the 24th, then I'll merge this and the other PR you opened.

Going to keep this open for a little bit longer since there was a recent comment.

@KyleBoyer
Copy link
Contributor Author

@kenhuuu sounds good, I'm just hoping to get it in before the next 3.7.X release!

Copy link

@kmcginnes kmcginnes left a comment

Choose a reason for hiding this comment

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

This is almost ready. I have 1 important change request, and 2 less important ones that might be subjective.

});
return connection.open();
});
Promise.allSettled(allOptionTests).then(function () {

Choose a reason for hiding this comment

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

If I'm not mistaken, this promise should be returned from the test function so that Jest waits on it properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, pushed the fix for this! Thank you :)

Promise.allSettled(allOptionTests).then(function () {
if (globalWebsocketCalls !== 0) {
assert.fail('global WebSocket should be used when no ws specific options are provided');
}

Choose a reason for hiding this comment

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

This may be subjective, but could this if statement be an assertion instead?

assert.equal(globalWebsocketCalls, 0, 'global WebSocket should be used when no ws specific options are provided');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed the change for this!

.finally(function () {
if (globalWebsocketCalls <= 0) {
assert.fail('global WebSocket should be used when no ws specific options are provided');
}

Choose a reason for hiding this comment

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

Same question for this if statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed the change for this!

@KyleBoyer
Copy link
Contributor Author

This is almost ready. I have 1 important change request, and 2 less important ones that might be subjective.

The changes requested have been pushed!

Thank you for reviewing :)

@KyleBoyer KyleBoyer requested a review from kmcginnes January 27, 2025 17:07
@kmcginnes
Copy link

LGTM!

+1

@Cole-Greer
Copy link
Contributor

Thanks again @KyleBoyer for your contributions. VOTE +1

@Cole-Greer Cole-Greer merged commit acd86c6 into apache:3.7-dev Jan 29, 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.

5 participants