Skip to content

Commit

Permalink
WIP: f1x #4
Browse files Browse the repository at this point in the history
  • Loading branch information
addievo committed Sep 21, 2023
1 parent e900b19 commit 511f0ac
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions tests/RPC.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as rpcUtilsMiddleware from '@/utils/middleware';
import {
ErrorRPC,
ErrorRPCHandlerFailed,
ErrorRPCParse,
ErrorRPCRemote,
ErrorRPCTimedOut,
} from '@/errors';
Expand Down Expand Up @@ -733,8 +734,7 @@ describe('RPC', () => {
await rpcServer.destroy();
await rpcClient.destroy();
});
/*
Test('RPC client times out before server', async () => {
test('RPC client times out before server', async () => {
// Generate test data (assuming fc.array generates some mock array)
const values = fc.array(rpcTestUtils.safeJsonValueArb, { minLength: 1 });

Expand All @@ -750,7 +750,12 @@ describe('RPC', () => {
meta: Record<string, JSONValue> | undefined,
ctx: ContextTimed,
): AsyncIterableIterator<JSONValue> {
yield* input;
ctx.signal.throwIfAborted();
const abortProm = utils.promise<never>();
ctx.signal.addEventListener('abort', () => {
abortProm.rejectP(ctx.signal.reason);
});
await abortProm.p;
};
}
// Set up a client and server with matching timeout settings
Expand All @@ -761,7 +766,7 @@ describe('RPC', () => {
logger,
idGen,

handlerTimeoutTime: 100,
handlerTimeoutTime: 400,
});
rpcServer.handleStream({
...serverPair,
Expand All @@ -781,24 +786,16 @@ describe('RPC', () => {
logger,
idGen,
});
const callerInterface = await rpcClient.methods.testMethod(
{timer: 5}
);
const callerInterface = await rpcClient.methods.testMethod({ timer: 300 });
const writer = callerInterface.writable.getWriter();
const reader = callerInterface.readable.getReader();
const value = JSON.stringify(5342);
await utils.sleep(10);
// Expect the client to time out first
await expect(writer.write({ value })).toResolve();
const readResult = await reader.read();
const receivedValue = readResult.value; // First 'value' is from read result, second 'value' is from the object
expect(receivedValue).toStrictEqual(value);
await expect(writer.write(values[0])).toResolve();
await expect(reader.read()).toReject();

await rpcServer.destroy();
await rpcClient.destroy();
});
*/
test('RPC client and server with infinite timeout', async () => {
// Set up a client and server with infinite timeout settings
const values = fc.array(rpcTestUtils.safeJsonValueArb, { minLength: 3 });
Expand Down

0 comments on commit 511f0ac

Please sign in to comment.