-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
feat: support serializing circular refs properly #11467
Conversation
@SimenB do you have any tips on how to debug this timeout failure? I've compared a good chunk of values in I figure there's a good chance the issue is that something doesn't support avoiding circular refs and so its just going around and around without ever returning, but I can't find what the actual thing is 😓 |
Huh, weird it times out on circle but not gh actions... does it time out locally? |
Yeah I was surprised by that too, but wasn't sure if it was running all the tests in GHA as doing It always times out locally for me. |
ah, right. circle runs in band which breaks probably, while GH actions run with workers. Try to run the failing test and e.g. all tests in |
You mean like |
@SimenB I think this is good to go logic-wise, it's just the weird timeout issue that's blocking it (which I am at a bit of a loss on) |
@G-Rath I changed the await waitUntil(({stderr, stdout}) => {
console.log({stderr, stdout});
return stderr.includes('Ran all test suites.');
}); and it logs an error
|
At the very least You can look at how I had a serializer at first in I think the concerns raised in that PR are valid though - not everybody using |
We need to make sure it fails when running in parallel as well though, that's weird... |
I agree long-term, but short-term am focusing on fixing first then will look to optimise for performance (partly because I couldn't an already existing "worker options" object being passed around that I could easily add to for this)
What do you mean by that? Is that what you were meaning here when you said "Running this test on its own is fine, but having 2 of them and running in test mode leads to", or is this something else? I'm just reacquainting myself with this PR and trying to figure out what the underlying issue is that I need to solve given you originally tried something similar but had to revert (in particular because the error looks nasty, and I'm not sure how you'd go about solving it but that could just be because I'm not understanding what is going on). So far I've managed to progress this by applying the stringify/parse to the missing places which looks to have done the job, except the snapshot is incorrect (which I'm assuming is because I've missing something else, given the snapshotted error is in This is the test failure message/snapshot diff
|
Codecov Report
@@ Coverage Diff @@
## main #11467 +/- ##
=======================================
Coverage 67.52% 67.52%
=======================================
Files 328 329 +1
Lines 17246 17254 +8
Branches 5071 5073 +2
=======================================
+ Hits 11645 11651 +6
- Misses 5568 5570 +2
Partials 33 33
Continue to review full report at Codecov.
|
@SimenB I think this is ready for you to take a look at to advise on next steps (since I have the tests passing, but not sure if that's enough to confirm this is the whole fix or if you want to go bug hunting given the problems with this in the past). The only test failing is the standard |
Yep, that's what I meant (I think 😅 been a while). |
That'd track with what I've been seeing in tests for eslint plugins: if I run a test for just one rule I don't get a "circular error" error. So then I guess this might not actually be complete yet since we don't have a test for doing that... |
@G-Rath I pushed up a commit using This should in theory also support Note that this fails type and unit tests, but that shouldn't be too painful. (there was #5613 which attempted a fancy version of this - using just the serializer aspect seems to have same performance) |
@SimenB sounds fine to me, I like that it lets us avoid having an extra dependency. What's required to move this forward? I'm happy to resolve the type errors, but don't think I'll be able to handle implementing a proper parallel test so might need you to do that, if that's something you want for this. |
When I played with this this morning, the test seems correct to me - 2 tests running in parallel |
Bah, just noticed this has the same issue as #10981 (comment) 🙁 I'll push a test for this |
OK, pushed that test to master, and merged here. It's failing 😭 We need to filter out functions somehow, but doesn't seem like the API supports it. I guess we could do some recursion, but still. |
When you say filter, are you meaning we want to pass them without serialising, or skip them all together? I think that's probably going to get complex fast... |
Skip them entirely, it's impossible to actually serialize them, so we need to remove them |
I think we can do this with |
Yeah, that's how |
My understanding is that Frankly either way it sounds like |
I swapped mainly as it should be faster as it's implemented in c++ and honed for years by google engineers. Benchmarking confirmed no real difference between using it and the current "raw" approach. And it passed the tests 😀 We could go for flatted, but it only fixes a subset of the issue (circular references) and not the underlying problem (inability to serialize complex objects). But it might be better to just go with |
I suspect the only true way to resolve that properly is going to be to have a pluggable system to let people provide their own serializer, given all the different ways an object could be structured, and the performance hits we might take if we tried to support all of them. I think the incremental approach is the right one for now - are you happy to do the benchmarking if I re-add |
I wonder if we should take a step back. In the case of failing tests in Jest, we attempt to serialize We might need to properly serialize that object in particular so it's in some representation that's safe to transfer between processes, and then just let Then probably bump minimum node 12 version from 12.13 to 12.16 so we can use https://nodejs.org/api/child_process.html#advanced-serialization (this is already the default in |
That sounds like a good path, but doesn't it just move the underlying problem to be higher up since we still have to deal with functions and other types that can't be serialized? (I think you're probably right though that that responsibility should be with whatever is calling |
Yes, but it should be up to the dependents to pass sane data to the worker. Like I think that by trying to work around it in |
Completely agree - so then is the next step to look into serializing |
I think we shouldn't try to serialize the instance, but rather make sure that a complete And the same for jasmine. So we might have to also tweak the reporter since the object it'll receive will be less rich |
@G-Rath is what we discussed above something you're willing to work on? 🙂 (No pressure of course, I just wanna know if I should add it to my TODO-list or not 😀 ) |
@SimenB I'm interested, but if you're ok having it on your todo I think that'd probably be better as I've already got a fair bit on and I think you'll have a better understanding of what needs to happen anyway. Keen to see the follow-up work though, so feel free to tag me for review and am happy to help so e.g. if there are isolated or follow-up improvements that could be done that I could help do let me know know |
@SimenB, @G-Rath I accidentally bumped into this one while investigating an issue we have in dom-testing-library for a while now: testing-library/dom-testing-library#875 Do you think this one might be related? @agmcleod was able to provide a reproduction but it still doesn't reproduce every time.. |
Yeah, probably |
Yeah, if you could pick up #11467 (comment) that'd be great! If you're able to unskip & we should be good 🙂 |
@SimenB I'll give it a try :) will update on any progress I make. |
Awesome, thanks! |
Hi @SimenB, just looping back to say it's taking me a bit longer to on-board to the project as I'm not too familiar with the codebase. Still didn't give up on this one but just wanted you to know :) |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
This is a really hacky attempt to kick off resolving issues with circular refs - right now I'm looking to figure out where the right place(s) to put things are, which'll be followed up by implementing support for
jest-worker
to take custom (de)serializers as described in this comment by @SimenBI would be doing this locally, but I'm suspect as I think I'm really close but for some reason the test is timing out and I can't pin down why.
If I remove the circular ref line (the
foo.ref = foo;
) the test passes fine both with and without my hack, but if it has a ref it fails with:Fixes #10577
Fixes #11617
Closes #11624
Test plan
Have the
handles circular inequality properly
test passing.