Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): bound slow-client event buffers #9715

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/9715/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Showing 6 changed files with 243 additions and 0 deletions (loading 4).

x
0 of 6 viewed, 6 left
47 additions and 0 deletionsapps/server/src/orchestration/LiveStreamBudget.test.tsAdded
View file
@@ -0,0 +1,47 @@
+import { it } from "@effect/vitest";
+import * as Deferred from "effect/Deferred";
+import * as Effect from "effect/Effect";
+import * as Queue from "effect/Queue";
+import * as Stream from "effect/Stream";
+import { describe, expect } from "vite-plus/test";
+​
+import { makeLiveStreamBudget, type RetainedLiveItem } from "./LiveStreamBudget.ts";
+​
+describe("LiveStreamBudget", () => {
+ it.effect("closes the source without releasing a batch still waiting for an ACK", () =>
+ Effect.scoped(
+ Effect.gen(function* () {
+ const budget = yield* makeLiveStreamBudget({ maxItems: 3 });
+ const queue = yield* Queue.unbounded<RetainedLiveItem<{ text: string }>>();
+ const sourceClosed = yield* Deferred.make<void>();
+ const first = yield* budget.retain({ text: "first" });
+ const second = yield* budget.retain({ text: "second" });
+ const third = yield* budget.retain({ text: "third" });
+ yield* Queue.offerAll(queue, [first, second, third]);
+ yield* Effect.scoped(
+ Effect.gen(function* () {
+ const pull = yield* Stream.toPull(
+ budget.deliver(
+ Stream.fromQueue(queue).pipe(
+ Stream.rechunk(1),
+ Stream.ensuring(Deferred.succeed(sourceClosed, undefined)),
+ ),
+ ),
+ );