Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
addievo committed Oct 20, 2023
1 parent 1bc5ac5 commit 695ed02
Showing 1 changed file with 3 additions and 82 deletions.
85 changes: 3 additions & 82 deletions tests/RPCServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ describe(`${RPCServer.name}`, () => {
}
await rpcServer.stop({ force: true });
});
test('handler overrides timeout - lesser value', async () => {
test('handlerTimeout overrides default timeout - greater value and lesser value', async () => {
{
const waitProm = promise();
const ctxShortProm = promise<ContextTimed>();
Expand All @@ -961,7 +961,7 @@ describe(`${RPCServer.name}`, () => {
}
const ctxLongProm = promise<ContextTimed>();
class TestMethodLongTimeout extends UnaryHandler {
handlerTimeout = 26;
handlerTimeout = 100;
public handle = async (
input: JSONValue,
_cancel,
Expand Down Expand Up @@ -1016,86 +1016,7 @@ describe(`${RPCServer.name}`, () => {

// Longer timeout is set to server's default
const ctxLong = await ctxLongProm.p;
expect(ctxLong.timer.delay).toEqual(26);
waitProm.resolveP();
await rpcServer.stop({ force: true });
}
});
test('handler overrides timeout - greater value', async () => {
{
const waitProm = promise();
const ctxShortProm = promise<ContextTimed>();
class TestMethodShortTimeout extends UnaryHandler {
handlerTimeout = 250;
public handle = async (
input: JSONValue,
_cancel,
_meta,
ctx_,
): Promise<JSONValue> => {
ctxShortProm.resolveP(ctx_);
await waitProm.p;
return input;
};
}
const ctxLongProm = promise<ContextTimed>();
class TestMethodLongTimeout extends UnaryHandler {
handlerTimeout = 261;
public handle = async (
input: JSONValue,
_cancel,
_meta,
ctx_,
): Promise<JSONValue> => {
ctxLongProm.resolveP(ctx_);
await waitProm.p;
return input;
};
}
const rpcServer = new RPCServer({
handlerTimeoutTime: 50,
logger,
idGen,
});
await rpcServer.start({
manifest: {
testShort: new TestMethodShortTimeout({}),
testLong: new TestMethodLongTimeout({}),
},
});
const streamShort = rpcTestUtils.messagesToReadableStream([
{
jsonrpc: '2.0',
method: 'testShort',
params: null,
},
]);
const readWriteStreamShort: RPCStream<Uint8Array, Uint8Array> = {
cancel: () => {},
readable: streamShort,
writable: new WritableStream(),
};
rpcServer.handleStream(readWriteStreamShort);
// Shorter timeout is updated
const ctxShort = await ctxShortProm.p;
expect(ctxShort.timer.delay).toEqual(250);
const streamLong = rpcTestUtils.messagesToReadableStream([
{
jsonrpc: '2.0',
method: 'testLong',
params: null,
},
]);
const readWriteStreamLong: RPCStream<Uint8Array, Uint8Array> = {
cancel: () => {},
readable: streamLong,
writable: new WritableStream(),
};
rpcServer.handleStream(readWriteStreamLong);

// Longer timeout is set to server's default
const ctxLong = await ctxLongProm.p;
expect(ctxLong.timer.delay).toEqual(261);
expect(ctxLong.timer.delay).toEqual(100);
waitProm.resolveP();
await rpcServer.stop({ force: true });
}
Expand Down

0 comments on commit 695ed02

Please sign in to comment.