|
| 1 | +import { expect, it } from "@effect/vitest"; |
| 2 | +import { |
| 3 | + EnvironmentId, |
| 4 | + ProjectId, |
| 5 | + TEXT_GENERATION_TIMEOUT_MS_FORK, |
| 6 | + THREAD_GROUP_TITLE_CLIENT_TIMEOUT_MS_FORK, |
| 7 | +} from "@t3tools/contracts"; |
| 8 | +import * as Effect from "effect/Effect"; |
| 9 | +import * as Fiber from "effect/Fiber"; |
| 10 | +import * as Option from "effect/Option"; |
| 11 | +import * as TestClock from "effect/testing/TestClock"; |
| 12 | +import { HttpClient } from "effect/http"; |
| 13 | + |
| 14 | +import { PrimaryConnectionTarget } from "../connection/model.ts"; |
| 15 | +import { fetchEnvironmentThreadGroupTitle } from "./threadGroupTitleHttp.ts"; |
| 16 | + |
| 17 | +it.effect("gives the server time to report its group-title deadline before the client aborts", () => |
| 18 | + Effect.gen(function* () { |
| 19 | + let interrupted = false; |
| 20 | + const client = HttpClient.make(() => |
| 21 | + Effect.never.pipe( |
| 22 | + Effect.onInterrupt(() => |
| 23 | + Effect.sync(() => { |
| 24 | + interrupted = true; |
| 25 | + }), |
| 26 | + ), |
| 27 | + ), |
| 28 | + ); |
| 29 | + const target = new PrimaryConnectionTarget({ |
| 30 | + environmentId: EnvironmentId.make("environment-1"), |
| 31 | + label: "Test environment", |
| 32 | + httpBaseUrl: "https://environment.example.test", |
| 33 | + wsBaseUrl: "wss://environment.example.test", |
| 34 | + }); |
| 35 | + const pending = yield* fetchEnvironmentThreadGroupTitle({ |
| 36 | + prepared: { |
| 37 | + environmentId: target.environmentId, |
| 38 | + label: target.label, |
| 39 | + httpBaseUrl: target.httpBaseUrl, |
| 40 | + socketUrl: "wss://environment.example.test/ws", |
| 41 | + httpAuthorization: null, |
| 42 | + target, |
| 43 | + }, |
| 44 | + signer: Option.none(), |
| 45 | + request: { projectId: ProjectId.make("project-1"), memberTitles: ["Ordering", "Groups"] }, |
| 46 | + }).pipe(Effect.provideService(HttpClient.HttpClient, client), Effect.flip, Effect.forkChild); |
| 47 | + yield* TestClock.adjust(TEXT_GENERATION_TIMEOUT_MS_FORK); |
| 48 | + expect(interrupted).toBe(false); |
| 49 | + yield* TestClock.adjust( |
| 50 | + THREAD_GROUP_TITLE_CLIENT_TIMEOUT_MS_FORK - TEXT_GENERATION_TIMEOUT_MS_FORK, |
| 51 | + ); |
| 52 | + expect(yield* Fiber.join(pending)).toMatchObject({ |
| 53 | + _tag: "RemoteEnvironmentAuthTimeoutError", |
| 54 | + timeoutMs: THREAD_GROUP_TITLE_CLIENT_TIMEOUT_MS_FORK, |
| 55 | + }); |
| 56 | + expect(interrupted).toBe(true); |
| 57 | + }), |
| 58 | +); |
0 commit comments