mirror of
https://github.com/Effect-TS/effect.git
synced 2026-12-06 03:59:09 +08:00
Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: Robin Brämer <robin.braemer@web.de> Co-authored-by: Robin Brämer <22003767+robinbraemer@users.noreply.github.com> Co-authored-by: Effect Bot <tech-ops@effectful.co>
45 lines
1.9 KiB
TypeScript
45 lines
1.9 KiB
TypeScript
import { assert, describe, it } from "@effect/vitest"
|
|
import { Effect } from "effect"
|
|
import { makeCluster } from "./harness.ts"
|
|
|
|
// After a restart nothing in these tests messages the entity before the
|
|
// rebuild is observed: the entity Durable Object has to wake on its own.
|
|
describe("Cloudflare cluster integration | KeepAlive recovery", () => {
|
|
it.live("rebuilds an entity holding keepAlive after an isolate restart", () =>
|
|
Effect.gen(function*() {
|
|
const cluster = yield* makeCluster
|
|
|
|
yield* cluster.fetchJson("/pinned/pin?id=recover")
|
|
yield* cluster.waitUntil(
|
|
"Entity.keepAlive(true) did not establish a hold on the entity Durable Object",
|
|
Effect.map(cluster.fetchJson("/holds?type=Pinned&id=recover"), (result) => result.holds === 1)
|
|
)
|
|
|
|
yield* cluster.restart
|
|
|
|
yield* cluster.waitUntil(
|
|
"The keep-alive entity was not rebuilt after the isolate restart",
|
|
Effect.map(cluster.fetchJson("/state"), (state) => (state.builds["Pinned/recover"] ?? 0) === 1)
|
|
)
|
|
yield* cluster.waitUntil(
|
|
"The rebuilt keep-alive entity did not hold its Durable Object again",
|
|
Effect.map(cluster.fetchJson("/holds?type=Pinned&id=recover"), (result) => result.holds === 1)
|
|
)
|
|
|
|
// Releasing keep-alive ends the recovery: the next restart leaves the
|
|
// entity cold.
|
|
yield* cluster.fetchJson("/pinned/unpin?id=recover")
|
|
yield* cluster.waitUntil(
|
|
"Releasing keepAlive did not unpin the entity Durable Object",
|
|
Effect.map(cluster.fetchJson("/holds?type=Pinned&id=recover"), (result) => result.holds === 0)
|
|
)
|
|
yield* cluster.restart
|
|
yield* Effect.sleep("2 seconds")
|
|
const state = yield* cluster.fetchJson("/state")
|
|
assert.isUndefined(
|
|
state.builds["Pinned/recover"],
|
|
"The entity was rebuilt after a restart although it had released keepAlive"
|
|
)
|
|
}), 60_000)
|
|
})
|