Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
cool
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT committed Oct 8, 2023
1 parent eb651f0 commit 11bd751
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/async/deserializeAsync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ test("1 iterator completed but another never finishes", async () => {
`);
});

test("e2e: server crash", async () => {
test("e2e: simulated server crash", async () => {
const crashedDeferred = createDeferred<null>();
function createMockObj() {
async function* generator() {
Expand Down Expand Up @@ -568,6 +568,7 @@ test("e2e: server crash", async () => {
const strIterarable = tson.stringify(obj, 4);

void crashedDeferred.promise.then(() => {
// destroy the response stream
res.destroy();
});

Expand All @@ -593,32 +594,33 @@ test("e2e: server crash", async () => {
(v) => textDecoder.decode(v),
);

let parsed: MockObj | null = null;
const results = [];
let iteratorError: Error | null = null;
try {
parsed = await tson.parse<MockObj>(stringIterator);
for await (const value of parsed.iterable) {
results.push(value);
const parsed = await tson.parse<MockObj>(stringIterator);
{
// check the iterator
const results = [];
let iteratorError: Error | null = null;
try {
for await (const value of parsed.iterable) {
results.push(value);
}
} catch (err) {
iteratorError = err as Error;
} finally {
server.close();
}
} catch (err) {
iteratorError = err as Error;
} finally {
server.close();
}

assert(iteratorError);
expect(iteratorError.message).toMatchInlineSnapshot(
'"Stream interrupted: terminated"',
);
assert(iteratorError);
expect(iteratorError.message).toMatchInlineSnapshot(
'"Stream interrupted: terminated"',
);
expect(results).toEqual([0, 1, 2, 3, 4, 5]);
}

assert(parsed);
expect(parsed.foo).toEqual("bar");
expect(await parsed.promise).toEqual(42);
await expect(
parsed.rejectedPromise,
).rejects.toThrowErrorMatchingInlineSnapshot('"Promise rejected"');
expect(results).toEqual([0, 1, 2, 3, 4, 5]);

expect(opts.onStreamError).toHaveBeenCalledTimes(1);

Expand All @@ -628,5 +630,5 @@ test("e2e: server crash", async () => {
"[TsonStreamInterruptedError: Stream interrupted: terminated]",
);

expect(streamError.cause).toMatchInlineSnapshot('[TypeError: terminated]');
expect(streamError.cause).toMatchInlineSnapshot("[TypeError: terminated]");
});

0 comments on commit 11bd751

Please sign in to comment.