Skip to content
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

Test nested event emission #102

Closed
wants to merge 1 commit into from
Closed

Test nested event emission #102

wants to merge 1 commit into from

Conversation

dshcherb
Copy link
Contributor

@dshcherb dshcherb commented Jan 12, 2020

I ran into an issue with the current object singularity tracking implementation when writing a test charm where I needed to emit an event in an event handler.

Example: on_start -> emit charm-specific event -> error.

This happens because of the current descriptor pattern implementation that creates new copies of EventsBase descendants by using type(self)(emitter):

....................E............................................
======================================================================
ERROR: test_weak_observer (test.test_framework.TestFramework)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ubuntu/src/juju/operator/test/test_framework.py", line 386, in test_weak_observer
    pub.on.foo.emit()
  File "/home/ubuntu/src/juju/operator/ops/framework.py", line 172, in emit
    framework._emit(event)
  File "/home/ubuntu/src/juju/operator/ops/framework.py", line 562, in _emit
    self._reemit(event_path)
  File "/home/ubuntu/src/juju/operator/ops/framework.py", line 597, in _reemit
    custom_handler(event)
  File "/home/ubuntu/src/juju/operator/test/test_framework.py", line 366, in on_foo
    self.on.bar.emit()
  File "/home/ubuntu/src/juju/operator/ops/framework.py", line 230, in __get__
    return type(self)(emitter)
  File "/home/ubuntu/src/juju/operator/ops/framework.py", line 223, in __init__
    super().__init__(parent, key)
  File "/home/ubuntu/src/juju/operator/ops/framework.py", line 201, in __init__
    self.framework._track(self)
  File "/home/ubuntu/src/juju/operator/ops/framework.py", line 413, in _track
    raise RuntimeError(f"two objects claiming to be {obj.handle.path} have been created")
RuntimeError: two objects claiming to be MyNotifier[1]/on have been created

The issue is also possible to trigger by using something like this:

        for e in (pub.on.foo,
                  pub.on.bar):
            framework.observe(e, obs)

@dshcherb
Copy link
Contributor Author

#99 should address this.

@dshcherb dshcherb closed this Jan 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant