-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
integration tests should use simulated time #4160
Comments
related: I'm wondering if there's a strong reason to have SystemTimeSource and MonotonicTimeSource as separate class hierarchies, as opposed to just having monotonicTime() and currentTime() as two separate methods on the same class? This might make injection a little less cumbersome. |
@jmarantz +1. Kill those statics! 😉
No reason. I would merge. |
Here's my rough plan:
|
…4226) The management of the timer_ variable in the test class was a little funky, and looked leak-prone. This PR cleans this up a little,. Without this PR, #4180 memory-leaks on this test, I think due to overwriting timer_. This is all toward resolution of #4160 Risk Level: Low. Testing: //test/common/config:grpc_mux_impl_test Docs Changes: n/a Release Notes: n/a Signed-off-by: Joshua Marantz <jmarantz@google.com>
This is one step toward addressing #4160 though this strategy may need to be backed out and re-worked. See the bug comments for more detail on the plan. The main value of this PR is to get rid of the Prod*TimeSource::instance_ statics, so we can inject time into tests. This PR doesn't actually inject time into tests differently; it just makes time injectable. Apologies about the gigantic PR. The follow-ups can be more incremental. Risk Level: medium: this should be non-functional, but a lot of lines of code changed. There is a fairly significant risk of merge issues too, so when merging, after this, we should be careful. Testing: //test/... Docs Changes: n/a Release Notes: n/a Signed-off-by: Joshua Marantz <jmarantz@google.com>
…ime from source. (#4248) Time should be injected in all production code, so that it can ultimately be tested using mock time or simulated time. Production code that directly instantiates ProdSystemTimeSource makes this impossible, and this PR ensures that 'format' checks fail if that is violated. This partially addresses issue #4160. Risk Level: low Testing: //test/... Docs Changes: n/a Release Notes: n/a Signed-off-by: Joshua Marantz <jmarantz@google.com>
Note to self:
|
Jotting down a rough roadmap to resolving this:
As I look at integration tests now, blocking with timeouts is done in the main test thread and it's not clear to me which thread should be advancing simulated time yet. |
…e with simulated timers (#4257) Unifies the TimeSource so that system and monotonic sources are always handled similarly (mocks, real-time, or in the future, simulated), and derives a new interface, Event::TimeSystem, which managers timers. This is a pure refactor; none of the operation or semantics of any production or test code is changed with this PR. This is another step in resolving #4160. Risk Level: medium, just because PR is large and merge conflicts happen, but it should be pretty safe Testing: //test/... Docs Changes: n/a Release Notes: n/a Signed-off-by: Joshua Marantz <jmarantz@google.com>
…stem() as appropriate (#4343) In #4257, Event::TimeSystem was introduced to augment the TimeSource abstraction to include timers. Most places in the system that had previously held onto a TimeSource held it in a member variable time_source_ and, if appropriate, exposed it as a method timeSource(), and #4257 changed those to Event::TimeSystem without renaming them, in order to minimize diffs. This PR just renames the members and methods to time_system_ and timeSystem() as appropriate. This is part of the chain of CLs to resolve #4160. Risk Level: low -- no functional risk, but depending on timing of when this gets merged, an easily-remedied build breakage could arise. Testing: //test/... Docs Changes: n/a Release Notes: n/a Signed-off-by: Joshua Marantz <jmarantz@google.com>
Can we leave this open? We still don't have steps 5 and 6 above done. |
Reopening as suggested by @jmarantz. |
One of the symptoms of this not being resolved, I suspect, is a tendency for this test to timeout sometimes: TIMEOUT: //test/extensions/filters/network/thrift_proxy:integration_test (Summary) |
…System or TimeSource (#4434) In order to fully control time during tests, direct calls to system-provided time functions must not be used. These had previously not been fixed. In at least one case I think there was real-time deltas being compared in a test, which really needed to be mocked, so that change had to occur in this PR. Another step toward resolution of #4160 Risk Level: medium, due to size of PR. Testing: //test/... Docs Changes: n/a Release Notes: n/a Signed-off-by: Joshua Marantz <jmarantz@google.com>
Add an alternate TimeSystem implementation which keeps manually-adjusted time and timer-callbacks making sense together. This is intended for use in most if not all unit tests, and many integration tests. This is another step to resolve #4160. Risk Level: low -- this is a new test-only class that's not used anywhere yet. Testing: //test/... Docs Changes: n/a Release Notes: n/a Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
This partially addresses envoyproxy#4160 Signed-off-by: Michael Puncel <mpuncel@squareup.com>
This partially addresses envoyproxy#4160 Signed-off-by: Michael Puncel mpuncel@squareup.com Description: Migrate to simulated time instead of real time in router tests Risk Level: low Testing: unit tests Docs Changes: n/a Release Notes: n/a Partially Fixes envoyproxy#4160 Signed-off-by: Fred Douglas <fredlas@google.com>
This was not fully closed. There are still a few barriers to enabling sim-time for all integration tests. |
As mentioned in #18157, |
We can only use one time system at a time, either a Simulated one or a Real one. The "GlobalTimeSystem" is just a helper class to get access to a time-system reference to the Real or Simulated system that already has been declared (or to declare a default real-time system if one is not already declared). To make a particular test use SimulatedTime you should only need to make its test-class derive from Event::TestUsingSimulatedTime, from test/test_common/simulated_time_system.h . You may experience issues with simulated time if there are parts of the test that depend on real time and don't provide a mechanism to inject time. One place I think this might come up with is gRPC which doesn't (afaik) provide a time-injection hook, but may use sleeps and real-time timeouts that don't work well with simulated time. In the absence of code under test with a dependence on real time elapsing, simulated time should make tests run faster with fewer flakes. |
FWIW, I haven't seen |
Description:
My feeling is that the root of this problem (and others) is singleton patterns like:
ProdMonotonicTimeSource::instance_
In the past I've used strategies where these get passed downward as the world gets constructed, so singletons are never referenced in code that needs to be tested (or even exist, usually).
My hope is that injecting MonotonicTime refs into key classes in the system will eliminate the need to reference singletons deeply.
The text was updated successfully, but these errors were encountered: