|
1 | 1 | import { expect, it } from "@effect/vitest"; |
2 | 2 | import * as Effect from "effect/Effect"; |
| 3 | +import * as Deferred from "effect/Deferred"; |
| 4 | +import * as Fiber from "effect/Fiber"; |
| 5 | +import { Deadline } from "@voidzero-dev/vite-plus-remote-cache-cloudflare/src/streams.ts"; |
3 | 6 | import * as Layer from "effect/Layer"; |
4 | 7 | import { vi } from "vite-plus/test"; |
5 | 8 | import { Observations } from "@voidzero-dev/vite-plus-remote-cache-cloudflare/src/observations.ts"; |
@@ -39,3 +42,49 @@ it.effect("includes successful blob downloads in exported R2 usage", () => |
39 | 42 | expect(observations.mock.results.at(-1)?.value.r2_operations).toBe(1); |
40 | 43 | }), |
41 | 44 | ); |
| 45 | + |
| 46 | +it.effect("aborts the upstream deadline before disposing it on interruption", () => |
| 47 | + Effect.gen(function* () { |
| 48 | + const entered = yield* Deferred.make<void>(); |
| 49 | + const cancelled: boolean[] = []; |
| 50 | + const originalDispose = Deadline.prototype.dispose; |
| 51 | + using _dispose = vi.spyOn(Deadline.prototype, "dispose").mockImplementation(function ( |
| 52 | + this: Deadline, |
| 53 | + ) { |
| 54 | + try { |
| 55 | + this.check(); |
| 56 | + cancelled.push(false); |
| 57 | + } catch { |
| 58 | + cancelled.push(true); |
| 59 | + } |
| 60 | + originalDispose.call(this); |
| 61 | + }); |
| 62 | + const bindings = { |
| 63 | + ARTIFACTS: { |
| 64 | + get: () => { |
| 65 | + Deferred.doneUnsafe(entered, Effect.void); |
| 66 | + return new Promise(() => {}); |
| 67 | + }, |
| 68 | + }, |
| 69 | + readLimit: { limit: async () => ({ success: true }) }, |
| 70 | + } as unknown as typeof Bindings.Service; |
| 71 | + yield* Effect.gen(function* () { |
| 72 | + const cache = yield* Cache; |
| 73 | + const fiber = yield* cache |
| 74 | + .handle( |
| 75 | + new Request( |
| 76 | + "https://cache.example/projects/t3code/blob/12345678-1234-1234-1234-123456789abc", |
| 77 | + ), |
| 78 | + { waitUntil: () => {} }, |
| 79 | + ) |
| 80 | + .pipe(Effect.forkChild); |
| 81 | + yield* Deferred.await(entered); |
| 82 | + yield* Fiber.interrupt(fiber); |
| 83 | + expect(cancelled).toEqual([true]); |
| 84 | + }).pipe( |
| 85 | + Effect.provide( |
| 86 | + layer.pipe(Layer.provide([Layer.succeed(Bindings, bindings), Admission.layer])), |
| 87 | + ), |
| 88 | + ); |
| 89 | + }), |
| 90 | +); |
0 commit comments