-
Notifications
You must be signed in to change notification settings - Fork 122
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
reinitialize charm on event in harness #835
Conversation
@sed-i @pengale @rwcarlsen WDYT? |
Looks good. Next, I would add tests for:
|
self._observers.clear() | ||
self._observer.clear() | ||
self._type_registry.clear() | ||
self._type_known.clear() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I don't think this is actually enough. AIUI the issue is that the Python code itself is actually adding bound methods to classes that point to this framework. So if we really wanted this, we would need to go around and remove all of those methods. (I'm not 100% sure what else, but there are a lot of Global modifications that are being done during initialization and registration of classes.)
raise RuntimeError('event needs to be bound to an emitter ' | ||
'sharing the same framework as this harness.') | ||
|
||
if REINITIALIZE_CHARM_ON_EVENT: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit concerned about these being module values. It means that if you have any test that starts opting into this behavior, suddenly the rest of your test suite becomes a bit indeterminate.
def emit_event(self, evt: BoundEvent, *args: Any, **kwargs: Any): | ||
"""Emit a bound event on the charm.""" | ||
if evt.emitter.framework is not self._framework: | ||
# namely, not sure what might happen if it doesn't. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment could be a bit clearer
a4e688d
to
caa0036
Compare
Just coming back to this, I don't think this is the right direction, due to the following issues:
Given those points, I tend to think we should move in the opposite direction of making it normal for the charm to expect multiple events. (We could still decide to create a new charm instance for every event, but I'm not sure that's a good signal.) Leaving this open for another couple of days in case @PietroPasotti has comments. |
I think I see your point, and can't quite wrap my head around a good reply. I think that never reinitializing the charm, even between two At the level of abstraction that the Harness operates, one could say, this is fine. If you want more realistic simulations, go to Scenario. I think of Scenario as a I can see why this level of detail is too much for harness, but I can't figure out why. |
Extended the Harness with an opt-in feature to reinitialize the charm on every event.
Documentation changes
This will likely have a moderate impact on user tests. It might reveal some bugs (which is good!), but it might also give some false negatives where people wrote tests (as we did too) using mock charms that attached state to the instance.
We need to communicate very clearly the scope of this change, and give time to adapt.
We should also probably add some api to hook into the harness' emit_event for recording purposes.
Bug reference
Bug: #736
Prior art: #758
Changelog