All Topics
All Topics
Technology
Technology
AI
AI
Business
Business
Entertainment
Entertainment
News
News
Programming
Programming
Security
Security
Science
Science
Design
Design
Environment
Environment
Finance
Finance
Crypto
Crypto
Politics
Politics
Sports
Sports
Education
Education
Gaming
Gaming
Art
Art
Music
Music
Health
Health
Books
Books
Food
Food
Travel
Travel
Personal
Personal
Bluesky
Twitter

Durable Objects, Workers - Test Durable Object eviction with new cloudflare:test helpers

10d ago

Source

CloudflareDurable Objects, Workers - Test Durable Object eviction with new cloudflare:test helperscloudflare.com
Snippet from the RSS feed
The @cloudflare/vitest-pool-workers package now includes evictDurableObject and evictAllDurableObjects test helpers, exported from cloudflare:test . These helpers let you test how a Durable Object behaves across evictions, simulating the production lifecycle where an idle Durable Object can be evicted from memory. For more context, refer to Lifecycle of a Durable Object . import { evictDurableObject , evictAllDurableObjects } from "cloudflare:test" ; import { env } from "cloudflare:workers" ; const id = env . COUNTER . idFromName ( "my-counter" ) ; const stub = env . COUNTER . get ( id ) ; // Evict the Durable Object instance pointed to by a specific stub await evictDurableObject ( stub ) ; // Close WebSockets instead of hibernating them await evictDurableObject ( stub , { webSockets : "close" } ) ; // Evict all currently-running Durable Objects in evictable namespaces await evictAllDurableObjects () ; These helpers are available in @cloudflare/[email protected] and later. Learn more in the Test APIs reference and the Testing Durable Objects guide .

You might also wanna read

Comments

Sign in to join the conversation.

No comments yet. Be the first.