mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-02 14:31:01 +02:00
Use tagged errors in tests
This commit is contained in:
parent
c4500f216e
commit
c48927b7c5
8 changed files with 104 additions and 23 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { describe, expect, it } from "@effect/vitest";
|
||||
import { ConfigProvider, Effect, Fiber } from "effect";
|
||||
import * as EffectChunk from "effect/Chunk";
|
||||
import * as S from "effect/Schema";
|
||||
import {
|
||||
MessagingRuntimeLive,
|
||||
PubSub,
|
||||
|
|
@ -18,6 +19,13 @@ import {
|
|||
import { ChunkingService } from "../chunking/service.js";
|
||||
import { recursiveSplit } from "../chunking/recursive-splitter.js";
|
||||
|
||||
class WaitForTimeout extends S.TaggedErrorClass<WaitForTimeout>()(
|
||||
"WaitForTimeout",
|
||||
{ label: S.String },
|
||||
) {}
|
||||
|
||||
const isWaitForTimeout = S.is(WaitForTimeout);
|
||||
|
||||
function createMessage<T>(value: T, properties: Record<string, string> = {}): Message<T> {
|
||||
return {
|
||||
value: () => value,
|
||||
|
|
@ -36,14 +44,14 @@ const waitFor = (condition: () => boolean, label: string) =>
|
|||
return;
|
||||
}
|
||||
if (Date.now() > deadline) {
|
||||
reject(new Error(`Timed out waiting for ${label}`));
|
||||
reject(WaitForTimeout.make({ label }));
|
||||
return;
|
||||
}
|
||||
setTimeout(check, 5);
|
||||
};
|
||||
check();
|
||||
}),
|
||||
catch: (error) => error,
|
||||
catch: (error) => isWaitForTimeout(error) ? error : WaitForTimeout.make({ label }),
|
||||
});
|
||||
|
||||
class RecordingProducer<T> implements BackendProducer<T> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue