-
Notifications
You must be signed in to change notification settings - Fork 662
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TestLoop] Vastly simplify LoopEventHandler (#10888)
This PR is based on #10884 . Previously, a `LoopEventHandler` provides the ability to (1) initialize, which emits some events before the test loop is run at all; (2) handle an event; (3) decide whether an event can be dropped, which is used to ignore periodic timers at the end of a test; (4) send another event of the same type back into the test loop. This PR removes (1), (3), (4), leaving `LoopEventHandler` with only the ability to handle events; in other words, it is simply a function now. Here are the use cases that needed to be tackled: * (1), (3), (4) were used to support periodic timers. Periodic timers were implemented by first emitting an initial event during (1), and then later when handling that event, it used (4) to send another event to trigger the next tick, and so on. When the test is dropped, (3) returns true for any periodic timer event remaining in the event loop, so that the test doesn't think there are unhandled events. * Now, periodic timers are supported via two mechanisms: (a) by using the production implementation based on `DelayedActionRunner`, which periodic timers have already been refactored to use; see `ShardsManager::periodically_resend_chunk_requests`; for (3), the `DelayedActionRunner` that the TestLoop provides (`TestLoopDelayedActionRunner`) will no longer send new events when the test loop itself is shutting down; for production, the `DelayedActionRunner` is implemented using the Actix context, which does nothing if the actix system is shutting down, so these two behaviors are consistent. (b) by scheduling a future that uses Clock::sleep. See #10884 . * (4) was used mostly for convenience, so that when creating a handler, we do not need to pass in a `DelaySender` that can be used to send another event back to the event loop. For example, `route_shards_manager_network_messages` handled events of the type `(usize, Event)`, and since (4) provided a way to send another `(usize, Event)` back to the event loop, the handler just worked. However, this came at a cost of extra complexity in implementing the test loop because the event handler needed some way to have a `DelaySender<(usize, Event)>` (in this example) to send the event, so (1) is needed to support that (during initialization, we store the sender in a local field of the event handler). * Now, (4) is removed and replaced with the need to explicitly pass in any `DelaySender`s needed (and also Clock, or the shutting down flag). This is not really a big deal, because these are available easily via `test.sender()` (maybe with a `.for_index(idx)` or `.narrow()` trail), `test.clock()`, `test.shutting_down()`. * Because of this explicitness, I've added helper functions (`register_delayed_action_handler` and its `_for_index` variant) to register handlers for the delayed actions case, because otherwise the code looks too long and cryptic.
- Loading branch information
1 parent
ea09a10
commit d92c69d
Showing
18 changed files
with
592 additions
and
697 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.