-
Notifications
You must be signed in to change notification settings - Fork 30.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
test: add tests for ensuring proper timer delays #7404
Conversation
Includes a passing test that should keep passing and an issue test to be fixed. Refs: nodejs#5426 Refs: nodejs#7346 Refs: nodejs#7386
As indicated by #5426 (comment) and confirmed by #5426 (comment), #5426 is fixed by #3063. |
Oh crap is this that issue again? Whoops.. |
That being said, these tests are still valuable, one in the mean time, the other because that behavior is not covered yet. |
I believe the tests in this PR already exist in part in #3063 and, as I mentioned previously in #3063 several times in one test added by #2232 that needs to be ported to #3063. |
@misterdjules Maybe for the known issue, yes. But the other test tests a behavior that we don't yet... |
Regarding However I'm not sure it is what it intends to test, since that file mentions #5426 (comment), which seems to describe another problem: the fact that code running on node's main thread offsets the time at which nested timers using the same delay fire. Is that comment still relevant? Also, does this test need to use one timer that is scheduled from within another timer's callback? if so, why? If the purpose of that test is indeed to test that timers fire after a duration that is within a margin of error of the delay that was set at the time of their creation, it seems that Regardless, it seems that both tests have a similar issue: picking an appropriate "margin of error" is subjective. Node.js' documentation only guarantees that the timers will fire after the delay, but isn't more specific. Moreover, it potentially makes the test flaky when running on a slower/heavily loaded machine. On a busy system, the node process that runs the test can be scheduled off CPU at any time and for an arbitrary duration between when the timer was scheduled and when its callback fires. It is likely that this problem wouldn't surface often, but it still indicates a design issue with both tests. Unfortunately I don't know how to solve it. I think these two issues are OK for the But if For instance, if a future change adds 150ms of delay to the time when every timer actually fires, which could be a regression, it seems that test wouldn't catch it in its current form. Maybe the solution is to lower the margin of error to a value that is lower, but that we empirically determine to not make the test too flaky. It might be tricky to make that work across all platforms. I think |
@misterdjules The test in question is to ensure that this patch does not appear to fix the problem, because it would create another problem that we do not yet test for. That being said I'm suspecting there is also another problem floating around that none of these tests catch: When large sync work is done, existing scheduled same-duration callbacks will be re-scheduled too late. That is, this inner logic from #3063 is correct, but it should (as I have said before) be put into this conditional. However, I am having a hard time testing that issue. |
If I understand correctly, we would add a test for some code that is not in the code base? I'm not sure I understand why that would be useful.
This seems to be what #3063 fixes.
May I ask you to comment in #3063 directly? I couldn't find any previous comment from you on that part of #3063. It seems to me that the best way to move forward would be to land #3063 after:
What do you think? |
Kinda? It's to make sure we don't regress it? |
OK, I got confused by the part that says:
but now I understand what you meant. As I mentioned before, and contrary to what its comments mention, that test ( I would suggest keeping only A test similar to |
I don't trust my tests here. Will continue to try to test this (issue no.2) at some point in the future. |
Checklist
make -j4 test
(UNIX) orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
tests, timers
Description of change
Adds some test cases for #5426 ... it's a pretty strange bug and I'm not immediately sure what is going on but it may be useful to have these in here so we don't accidentally regress while trying to fix it.
Includes a passing test that should keep passing and an issue test to
be fixed.
Note: I think the known_issues test is testing the correct thing, but verification would be helpful.
See also: #7346 & #7386
cc @nodejs/testing and also @misterdjules