Improve two-way communication test#621
Open
Nemikolh wants to merge 1 commit intoGoogleChromeLabs:mainfrom
Open
Improve two-way communication test#621Nemikolh wants to merge 1 commit intoGoogleChromeLabs:mainfrom
Nemikolh wants to merge 1 commit intoGoogleChromeLabs:mainfrom
Conversation
This commit improves the test to capture clone errors that occured in v4.3.1 (or lower) when trying to do two-way communication. To do this, we expose a NonCloneable object that contains a MessagePort. In v4.3.1 when `proxy` is called, the listener attached by `Comlink.expose` also gets called by the remote and does not perform an early return. Instead it attempt to do a postMessage with the raw value set to the NonCloneable instance. This throw an unhandledrejection. With this new test we verify that this does not happen.
Nemikolh
commented
Feb 23, 2023
Comment on lines
-37
to
-38
| PROXY = "PROXY", | ||
| THROW = "THROW", |
Author
There was a problem hiding this comment.
I've removed those because they are unused. If you'd rather keep them, let me know and I will update my PR.
Nemikolh
commented
Feb 23, 2023
Comment on lines
+58
to
+59
| expect(await proxy(1, 3)).to.equal(5); | ||
| // await new Promise((res) => res()); |
Author
There was a problem hiding this comment.
I tried to replace expect(await proxy(1, 3)).to.equal(5); with a simple await on an empty promise but that's not enough to see the error. I'm not exactly sure why.
Nemikolh
commented
Feb 23, 2023
| let called = false; | ||
| let notcalled = true; | ||
| let error = ""; | ||
| window.addEventListener("unhandledrejection", (ev) => { |
Author
There was a problem hiding this comment.
That's how we get notified in this test that Comlink try to do a postMessage (from the Comlink.expose event listener) that it shouldn't (but it does in v4.3.0 because of the overlap between WireValueType and MessageType).
In order to get an exception, we're forcing here Comlink to do a postMessage on an object that can't be cloned.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello! 👋
TLDR;
This PR improves the two-way communication test to fail if
WireValueTypeandMessageTypewould happen to overlap again in the future.Full story
First, I want to thank you for your work on Comlink. This is one of the most elegant, well written library I've ever come across ⭐ 👏
I recently noticed that the test for two-way communication does not do enough work to actually fail in versions of
Comlink< 4.3.1. I encountered this issue while trying to port two-way communication to our fork which is stuck at 4.3.0.To see how this PR helps you can use this bash script:
If you run this script you'll see this error in your console (you might need to scroll up a bit 📜):
If you run the script again but replace
BRANCH=fix-two-way-iframe-testbyorigin/main(or equivalent), you can see that the test pass (you'll need to scroll up again to view the result of the firstkarma start):This shows that the test is missing a few bits.