Open History to see the last commit
1import { expect, it } from "@effect/vitest";
2import * as Context from "effect/Context";
3import * as Deferred from "effect/Deferred";
4import * as Effect from "effect/Effect";
5import * as Option from "effect/Option";
6import * as Tracer from "effect/Tracer";
7
8import { forkParked, ServerActivation, withoutAmbientParentSpan } from "./serverActivation.ts";
9
10it.effect("proves a root is parked before returning and releases it with one gate", () =>
11 Effect.scoped(
12 Effect.gen(function* () {
13 const activation = yield* Deferred.make<void>();
14 const ran = yield* Deferred.make<void>();
15
16 yield* forkParked(Deferred.succeed(ran, undefined)).pipe(
17 Effect.provideService(ServerActivation, Deferred.await(activation)),
18 );
19 expect(yield* Deferred.isDone(ran)).toBe(false);
20
21 yield* Deferred.succeed(activation, undefined);
22 yield* Deferred.await(ran);
23 expect(yield* Deferred.isDone(ran)).toBe(true);
24 }),
25 ),
26);
27
28it.effect("withoutAmbientParentSpan drops inherited ParentSpan for long-lived roots", () =>
29 Effect.gen(function* () {
30 const ambient = Tracer.externalSpan({
31 traceId: "00000000000000000000000000000001",
32 spanId: "0000000000000001",
33 sampled: true,
34 });
35
36 const sawParent = yield* Effect.serviceOption(Tracer.ParentSpan).pipe(
37 Effect.map(Option.isSome),
38 withoutAmbientParentSpan,
39 Effect.provideService(Tracer.ParentSpan, ambient),
40 );
41
42 expect(sawParent).toBe(false);
43
44 const stillHasParent = yield* Effect.serviceOption(Tracer.ParentSpan).pipe(
45 Effect.map(Option.isSome),
46 Effect.provideService(Tracer.ParentSpan, ambient),
47 );
48 expect(stillHasParent).toBe(true);
49
50 const stripped = Context.omit(Tracer.ParentSpan)(Context.make(Tracer.ParentSpan, ambient));
51 expect(Option.isNone(Context.getOption(stripped, Tracer.ParentSpan))).toBe(true);
52 }),
53);