Skip to content

Commit 511f0ac

Browse files
committed
WIP: f1x #4
1 parent e900b19 commit 511f0ac

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

tests/RPC.test.ts

+12-15
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import * as rpcUtilsMiddleware from '@/utils/middleware';
1414
import {
1515
ErrorRPC,
1616
ErrorRPCHandlerFailed,
17+
ErrorRPCParse,
1718
ErrorRPCRemote,
1819
ErrorRPCTimedOut,
1920
} from '@/errors';
@@ -733,8 +734,7 @@ describe('RPC', () => {
733734
await rpcServer.destroy();
734735
await rpcClient.destroy();
735736
});
736-
/*
737-
Test('RPC client times out before server', async () => {
737+
test('RPC client times out before server', async () => {
738738
// Generate test data (assuming fc.array generates some mock array)
739739
const values = fc.array(rpcTestUtils.safeJsonValueArb, { minLength: 1 });
740740

@@ -750,7 +750,12 @@ describe('RPC', () => {
750750
meta: Record<string, JSONValue> | undefined,
751751
ctx: ContextTimed,
752752
): AsyncIterableIterator<JSONValue> {
753-
yield* input;
753+
ctx.signal.throwIfAborted();
754+
const abortProm = utils.promise<never>();
755+
ctx.signal.addEventListener('abort', () => {
756+
abortProm.rejectP(ctx.signal.reason);
757+
});
758+
await abortProm.p;
754759
};
755760
}
756761
// Set up a client and server with matching timeout settings
@@ -761,7 +766,7 @@ describe('RPC', () => {
761766
logger,
762767
idGen,
763768

764-
handlerTimeoutTime: 100,
769+
handlerTimeoutTime: 400,
765770
});
766771
rpcServer.handleStream({
767772
...serverPair,
@@ -781,24 +786,16 @@ describe('RPC', () => {
781786
logger,
782787
idGen,
783788
});
784-
const callerInterface = await rpcClient.methods.testMethod(
785-
{timer: 5}
786-
);
789+
const callerInterface = await rpcClient.methods.testMethod({ timer: 300 });
787790
const writer = callerInterface.writable.getWriter();
788791
const reader = callerInterface.readable.getReader();
789-
const value = JSON.stringify(5342);
790-
await utils.sleep(10);
791792
// Expect the client to time out first
792-
await expect(writer.write({ value })).toResolve();
793-
const readResult = await reader.read();
794-
const receivedValue = readResult.value; // First 'value' is from read result, second 'value' is from the object
795-
796-
expect(receivedValue).toStrictEqual(value);
793+
await expect(writer.write(values[0])).toResolve();
794+
await expect(reader.read()).toReject();
797795

798796
await rpcServer.destroy();
799797
await rpcClient.destroy();
800798
});
801-
*/
802799
test('RPC client and server with infinite timeout', async () => {
803800
// Set up a client and server with infinite timeout settings
804801
const values = fc.array(rpcTestUtils.safeJsonValueArb, { minLength: 3 });

0 commit comments

Comments
 (0)