Add concurrency test
Lint / lint (push) Failing after 11s

This commit is contained in:
Julien Valverdé
2026-05-26 21:13:44 +02:00
parent 33a941b448
commit cdc390cde6
+25
View File
@@ -208,6 +208,31 @@ describe("Lens", () => {
expect(result[1]).toBe(25) expect(result[1]).toBe(25)
}) })
test("modifyEffect updates are atomic under concurrency", async () => {
const iterations = 100
const result = await Effect.runPromise(Effect.flatMap(
SubscriptionRef.make({ count: 0 }),
parent => {
const countLens = Lens.focusObjectOn(Lens.fromSubscriptionRef(parent), "count")
return Effect.flatMap(
Effect.forEach(
Array.from({ length: iterations }),
() => Lens.updateEffect(
countLens,
count => Effect.as(Effect.yieldNow(), count + 1),
),
{ concurrency: "unbounded", discard: true },
),
() => parent.get,
)
},
))
expect(result.count).toBe(iterations)
})
test("focusObjectOn focuses a nested property without touching other fields", async () => { test("focusObjectOn focuses a nested property without touching other fields", async () => {
const [initialCount, updatedState] = await Effect.runPromise( const [initialCount, updatedState] = await Effect.runPromise(
Effect.flatMap( Effect.flatMap(