-
Notifications
You must be signed in to change notification settings - Fork 8
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
Reworked pre/post event hooks --> welcome emitter #54
Conversation
Haven't looked at the code yet, but two questions first:
|
yes, totally. My bad
I thought it would be less confusing to have separate terminology for the 'Context-context-manager' api. I'm afraid it might be hard to tell Ideally I'd like a more descriptive name for what the context manager is doing, but "context" is already confusing because of the Context object, so I think Context.context() is a bad idea. More ideas:
|
It's a little bit cutesy, but how about Is there a reason to disallow multiple with ctx.manager(State()) as manager:
# ... pre
manager.run("install")
# assert stuff
manager.run("start")
# ... post Or is that disallowed because it's against the Scenario spirit of "one event per test"? |
I've just skimmed the implementation, but I'm wondering why generators need to be involved? Modifying class Manager:
def __enter__(self):
self.emit_event, self.cleanup = main.setup()
return self
def run(self):
self.emit_event()
def __exit__(self, exc_type, exc_val, exc_tb):
self.cleanup() The Seems more direct to me, and no generators involved. |
very cheeky. Love it!
It is disallowed, and because of principles and because the Context keeps some state that needs to be cleaned up between event emissions (the juju log, emitted events). It's hard to reason about what these would mean if you have to second-guess how many juju events have been emitted in the lifetime of a context |
I did consider it, but was hesitant to modify
But I agree that the generator stuff introduces a whole lot more complexity than necessary when we could bite the bullet and break main up instead. |
It's actually more complicated than breaking ops.main up in three sections. We need to be able to interrupt the execution not only of ops.main but also of context._exec. Not sure how to do that |
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.
Looks reasonable to me. Left a few minor comments.
We need to be able to interrupt the execution not only of ops.main but also of context._exec
I'm still a bit unsure of why we need generators. What do you mean by the above -- is that referring to Context._exec_ctx
/ Runtime.exec
?
Either way, I'm not going to push back more about a slightly tricky implementation -- the user-facing API seems reasonable.
Pardon, I meant Runtime.exec.
To be clear, I agree that the implementation is not nice and I'm totally up for a refactoring, I just have no idea how to do it better. I already spent quite a lot of time breaking my head on it but I'm not sure how to get it done in a nicer way. Will work on a MWE of the situation so we can see if we find a better pattern. |
@benhoyt after pouring some more hours on the problem and reorganizing a bit the mocked ops main module, I came up with a solution where instead of everything being a generator, everything is a context manager. |
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.
Yeah, I think this implementation is more direct and easier to understand -- thanks!
Fixes #53