Make test helpers for simulating common scenarios
See original GitHub issueWe already have harness.begin_with_initial_hooks()
which simulates a “normal” sequence of bootup events for a charm in testing. But there are other important sequences of hooks/state-change that are important for charms to support - e.g. is container.can_connect
true or false (#691), relation join events coming in different orders, when does pebble-ready fire w.r.t. install, etc. This could also be potentially related to a medium+ term solution for resolving other issues such as #678 and https://github.com/canonical/operator/issues/456.
It should be possible to come up with a nice, extensible way to allow charmdevs to select one or more options from a grab-bag of event/state sequence scenarios, tweak them to their own liking and fire them off just like begin_with_initial_hooks
.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:10 (10 by maintainers)
Top GitHub Comments
I based that suggestion on the fact that
begin_with_initial_hooks
at the moment has a bunch ofrandom.shuffle()
s in place to discourage the harness user from relying on the event ordering; although if you ask me this might lead to unpredictable and hard-to-debug failures if there is in fact some bug in the charm. So I’m in favour of removing that.Worked out something which might help or inspire whoever works this out eventually
https://discourse.charmhub.io/t/on-fuzzing-a-charms-lifecycle/5821
https://github.com/PietroPasotti/charm-events/blob/main/simulator.py