Skip to content

feat: run a charm's events in a persistent worker process for ops.testing - #2902

Draft
tonyandrewmeyer wants to merge 2 commits into
canonical:mainfrom
tonyandrewmeyer:saddle/split-02-worker
Draft

tonyandrewmeyer wants to merge 2 commits into
canonical:mainfrom
tonyandrewmeyer:saddle/split-02-worker

Conversation

@tonyandrewmeyer

@tonyandrewmeyer tonyandrewmeyer commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Adds a private worker that runs one charm's events in a separate Python process, with the event and State crossing as JSON (the encoding from #2828), so that charms whose dependencies conflict can be tested together.

  • scenario._isolation.Worker is what the multi-charm model will hold, one per application. It reads the charm's metadata from disk and never imports the charm in the test process. It starts the worker process on the first event and keeps it for later ones, and the unit ID comes with each event, so one process serves every unit.
  • A worker that crashes or takes longer than the timeout (60 seconds by default) is killed, raises IsolationError, and isn't restarted. A charm that raises is different: the worker sends the traceback back and stays usable.
  • Messages are length-prefixed rather than line-delimited, and the worker moves its responses off file descriptor 1, which it points at stderr, because charms write to fd 1 through subprocesses and C extensions as well as print.
  • IsolationError is private for now, in scenario._juju_errors, and feat: add a typed JSON encoding of ops.testing State for worker processes #2828's version error is now a subclass of it. IsolationError moves to testing.errors when the API is exposed.

Some things the proof of concept had are left out: a mode that starts a new process for every event, an idle timer, charm mocking, per-unit filesystems, and telling a charm's own exception apart from a worker failure. Those come in later PRs in the series.

The tests run the worker with fixture charms, including two that need conflicting versions of the same dependency, one that exits the process, one that never returns, and one that writes to fd 1.

tonyandrewmeyer and others added 2 commits November 15, 2026 13:35
…ting

Adds a private worker that runs one charm's events in its own interpreter,
with the event and State crossing as JSON, so that charms with conflicting
dependencies can be tested together. One worker serves every unit of an
application, and is kept between events. A worker that crashes or times
out raises IsolationError and isn't restarted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Closing stdin flushes it, so after a write to a worker that had died the
close raised BrokenPipeError and left stdout and stderr open. Adds tests
for a worker that dies between events and for a charm module with no
charm class or two, and drops python_path, which nothing uses yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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