Issue #1845: Initial support for Simulation in Tokio #2047
Closed
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.
Opening this draft PR for now to facilitate collaboration in finding a suitable API to expose. Eventually, I think we will want to move the majority of Simulation components outside of the Tokio repository, for now I've included them until we can arrive at a suitable API.
Motivation
More context can be found in #1845
The motivation for this work is to provide support for FoundationDB style simulation testing with Tokio. The goal is to provide users a low friction API for introducing deterministic simulation testing to their existing applications.
Solution
Time
When simulation testing is enabled, the time driver replaces all
Park::park_timeout
calls to it's innerPark
with aPark::park_timeout
duration of 0, advancing a mocked clock by the originalPark::park_timeout
duration. This results in the runtime only advancing time if there are no more tasks which can make progress.TcpStream
andTcpListener
Both the
TcpStream
andTcpListener
have had their internalPollEvented
hidden behind anenum
which allows for swapping inSimTcpStream
andSimTcpListener
when under simulation. The calls to construct and register these TCP types have been moved into the I/O driver handle. The I/O driver handle has been made to be based off anenum
also, which allows for constructing Simulation types when simulation mode is enabled.Todo
Aside from settling on an interface for plugging in the Simulation crate, there is quite a bit of work left to cleanup the types, address
todo!()
's, fix feature flags, and reintroduce disabled tests. Also, there is notokio::spawn
wrapping yet, and as a result, simulated DNS assumes there is only 1 address, which is localhost.