Skip to content

test(examples): suspend and resume a MicroVM - #839

Merged
ParidelPooya merged 3 commits into
mainfrom
test/microvm-session-suspend-resume
Oct 25, 2026
Merged

ParidelPooya merged 3 commits into
mainfrom
test/microvm-session-suspend-resume

Conversation

@ParidelPooya

@ParidelPooya ParidelPooya commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR adds a MicroVM example and a cloud test in which a session MicroVM suspends itself between two jobs, and the second job resumes it.

Why

  1. The existing session example sends two jobs without auto-suspend.
  2. So no cloud test ran the suspend path: the worker's SuspendMicrovm call, the suspend and resume hooks, and the request step's GetMicrovm and ResumeMicrovm state check.
  3. This test runs that path against the service.

Changes

  • New example src/microvm/microvm_session_suspend.py, catalog name "MicroVM Session Suspend".
    • A microvm_session with auto_suspend_on_idle=True and an idle time of 10 seconds.
    • Job 1 writes a file through /write. A callback named gate follows. Job 2 reads the file through /read.
    • The caller completes gate to start job 2. The gate times out after 5 minutes, so a caller that never completes it leaves the MicroVM running for 5 minutes at most.
  • New cloud-only test test/microvm/test_microvm_session_suspend.py.
    1. It starts the execution with run_async.
    2. It reads the MicroVM ID from the launch step in the execution history. A list of the image's MicroVMs could name another test's MicroVM.
    3. It waits for the gate callback ID.
    4. It polls GetMicrovm until it sees SUSPENDED. Job 1 has ended, and job 2 cannot start while gate is pending. So the observed suspend lies between the two jobs, whatever the timing.
    5. It completes gate, and waits for the result.
    6. It checks that both jobs ran in the same MicroVM, that the second job read the file that the first job wrote, the operation tree, resumeBeforeDelivery in the launch result, and that the MicroVM was terminated.
    • If the test fails before it completes gate, it fails the callback. So the session terminates the MicroVM at once.
  • Helpers in microvm_helpers.py: wait_for_history_event, find_launched_microvm_id on top of it, wait_for_microvm_state, and fail_callback_after_test_failure, with unit tests.
  • No change to the image, app.py, or the image settings.

Permissions

  • The function role needs lambda:GetMicrovm and lambda:ResumeMicrovm.
  • The MicroVM execution role needs lambda:SuspendMicrovm on the image.

Testing

  • Cloud run in a development account, with a new image built from this branch: the new test and both existing MicroVM tests passed, in 47 seconds. All MicroVMs ended TERMINATED.
  • hatch run dev-examples:test: 189 passed, 6 skipped. The new test is skipped in local mode. hatch fmt --check passes.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

The new session example lets its idle MicroVM suspend during a 60-second
wait. Its cloud test reads the MicroVM ID from the launch step, sees the
state SUSPENDED, and checks that the next job resumed the same MicroVM.
This addresses the review of the suspend test. The test now reads the
MicroVM state only after the pause wait has started in the history.

@yaythomas yaythomas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Permissions section contains internal-only review and test-account details. This repository is public, and the README already lists the public IAM actions. Can that section keep only the public permission list?

Address review: a callback named gate replaces the 60-second wait. The
test completes the gate only after it sees SUSPENDED, so the suspend
lies between the jobs with no timing assumption. A failed test fails
the gate, so the session terminates the MicroVM.
@ParidelPooya

Copy link
Copy Markdown
Contributor Author

Thanks. I removed the internal details from the Permissions section. It now lists only the public IAM actions.

@yaythomas yaythomas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@ParidelPooya
ParidelPooya marked this pull request as ready for review October 25, 2026 22:08
@ParidelPooya
ParidelPooya merged commit ab740c4 into main Oct 25, 2026
29 checks passed
@ParidelPooya
ParidelPooya deployed to ai-pr-review-runtime October 25, 2026 22:08 — with GitHub Actions Active
@ParidelPooya
ParidelPooya deleted the test/microvm-session-suspend-resume branch October 25, 2026 22:08

This branch was successfully deployed

1 active deployment
ai-pr-review-runtime — be283c54 Deployed Oct 25, 2026 by ParidelPooya via notify / Generate notification summary #299
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.

2 participants