Skip to content

[Durable Objects] Add docs & changelog for eviction helpers in vitest#31686

Draft
apeacock1991 wants to merge 1 commit into
productionfrom
apeacock/do-eviction
Draft

[Durable Objects] Add docs & changelog for eviction helpers in vitest#31686
apeacock1991 wants to merge 1 commit into
productionfrom
apeacock/do-eviction

Conversation

@apeacock1991

@apeacock1991 apeacock1991 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds docs and changelog for the new vitest helpers, which allow the testing of evictions with Durable Objects.

The implementation PR can be found here: cloudflare/workers-sdk#14398.

Note: I updated two unrelated examples because they actually failed when ran, and all the new examples have been tested and pass.

Documentation checklist

@github-actions github-actions Bot added product:workers Related to Workers product product:durable-objects Durable Objects: https://developers.cloudflare.com/workers/learning/using-durable-objects/ product:changelog size/m labels Jun 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:

Pattern Owners
/src/content/changelog/ @cloudflare/pm-changelogs, @cloudflare/product-owners
/src/content/docs/durable-objects/ @elithrar, @rita3ko, @irvinebroque, @vy-ton, @iglesiasbrandon, @joshthoward, @danlapid, @oxyjun, @lambrospetrou, @mikenomitch, @cloudflare/product-owners
/src/content/docs/workers/ @cloudflare/workers-docs, @GregBrimble, @irvinebroque, @mikenomitch, @korinne, @WalshyDev, @cloudflare/deploy-config, @cloudflare/product-owners, @cloudflare/wrangler, @MattieTK, @cloudflare/dev-plat-leads, @vy-ton

@iglesiasbrandon

Copy link
Copy Markdown
Collaborator

/bonk review this pr

@ask-bonk

ask-bonk Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

This is a well-structured PR. The documentation is clear, the examples are practical, and the fixes to existing snippets are appreciated. A few notes:

src/content/docs/durable-objects/examples/testing-with-durable-objects.mdx

  • Good fix changing expect(ids.length).toBe(2) to .toBeGreaterThanOrEqual(2) in the listDurableObjectIds test — that's a realistic failure mode when other tests have created objects.
  • The eviction examples nicely demonstrate the difference between in-memory and durable state. The WebSocket hibernation/close examples are particularly useful.
  • Nit: Consider updating the reviewed: 2023-08-08 frontmatter date since this is a substantial content addition.

src/content/docs/workers/testing/vitest-integration/test-apis.mdx

  • Good job backfilling docs for reset() and abortAllDurableObjects() alongside the new eviction helpers.
  • The DurableObjectEvictionOptions table is clear and concise.
  • The evictDurableObject code example is self-contained and correctly shows the persisted-count behavior.

src/content/changelog/workers/2026-06-25-durable-object-eviction-test-helpers.mdx

  • Clean, to-the-point changelog entry. The inline example covers both single-object eviction and the webSockets option, which is exactly what readers need.

src/content/docs/workers/testing/index.mdx

  • Comparison matrix update is correctly placed.

Overall this looks ready to land. Nice work on testing the examples. 👍

github run

@apeacock1991 apeacock1991 force-pushed the apeacock/do-eviction branch from 70e3470 to 5e43ed1 Compare June 25, 2026 14:18

The `@cloudflare/vitest-pool-workers` package now includes `evictDurableObject` and `evictAllDurableObjects` test helpers, exported from `cloudflare:test`. These helpers let you exercise how a Durable Object behaves across evictions in your tests.

Eviction is graceful: durable storage is preserved, in-memory state is reset by tearing down the instance, hibernatable WebSockets are hibernated rather than closed, and eviction waits up to 30 seconds for in-flight requests to drain.

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.

As a user, I would ask "is this different than remote production behavior" because you're calling out all these things.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the references to durable storage

date: 2026-06-25
---

The `@cloudflare/vitest-pool-workers` package now includes `evictDurableObject` and `evictAllDurableObjects` test helpers, exported from `cloudflare:test`. These helpers let you exercise how a Durable Object behaves across evictions in your tests.

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.

These helpers let you exercise how a Durable Object behaves across evictions in your tests.

add something to help users why you would want to do this

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.

+1 and link to something that gives context on evictions maybe?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good shout, linked to the lifecycle doc now + gave some context on why


### Testing eviction

Use `evictDurableObject()` to gracefully evict a Durable Object instance during tests. Eviction tears down the instance to reset its in-memory state, while preserving durable storage. This lets you test how your Durable Object recovers state from storage after being evicted.

@vy-ton vy-ton Jun 25, 2026

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.

avoid graceful everywhere?

why callout saving durable storage? - if you do should be to highlight thats the product capability. otherwise I wonder "is my storage not durable"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair, removed the graceful parts. They are in there because of the abort functionality, which is non-graceful but I think we can just stick with "non-graceful" or similar in the abort part.

Comment thread src/content/docs/durable-objects/examples/testing-with-durable-objects.mdx Outdated
@apeacock1991 apeacock1991 force-pushed the apeacock/do-eviction branch from 5e43ed1 to b9e2478 Compare June 25, 2026 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product:changelog product:durable-objects Durable Objects: https://developers.cloudflare.com/workers/learning/using-durable-objects/ product:workers Related to Workers product size/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.