Skip to content

Commit

Permalink
fix: tests now have proper long and short test
Browse files Browse the repository at this point in the history
  • Loading branch information
addievo committed Oct 20, 2023
1 parent 695ed02 commit 992d374
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions tests/RPCServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -942,11 +942,12 @@ describe(`${RPCServer.name}`, () => {
}
await rpcServer.stop({ force: true });
});
test('handlerTimeout overrides default timeout - greater value and lesser value', async () => {
test('handler overrides timeout - lesser value', async () => {
{
const waitProm = promise();
const ctxShortProm = promise<ContextTimed>();
class TestMethodShortTimeout extends UnaryHandler {
// This will override the default timeout from 50 to 25, thereby decreasing it.
handlerTimeout = 25;
public handle = async (
input: JSONValue,
Expand All @@ -959,20 +960,6 @@ describe(`${RPCServer.name}`, () => {
return input;
};
}
const ctxLongProm = promise<ContextTimed>();
class TestMethodLongTimeout extends UnaryHandler {
handlerTimeout = 100;
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,
Expand All @@ -981,7 +968,6 @@ describe(`${RPCServer.name}`, () => {
await rpcServer.start({
manifest: {
testShort: new TestMethodShortTimeout({}),
testLong: new TestMethodLongTimeout({}),
},
});
const streamShort = rpcTestUtils.messagesToReadableStream([
Expand All @@ -1000,6 +986,36 @@ describe(`${RPCServer.name}`, () => {
// Shorter timeout is updated
const ctxShort = await ctxShortProm.p;
expect(ctxShort.timer.delay).toEqual(25);
}
});
test('handler overrides timeout - greater value', async () => {
{
const waitProm = promise();
const ctxLongProm = promise<ContextTimed>();
class TestMethodLongTimeout extends UnaryHandler {
// This will override the default timeout from 50 to 250, thereby increasing it.
handlerTimeout = 250;
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: {
testLong: new TestMethodLongTimeout({}),
},
});
const streamLong = rpcTestUtils.messagesToReadableStream([
{
jsonrpc: '2.0',
Expand All @@ -1016,7 +1032,7 @@ describe(`${RPCServer.name}`, () => {

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

0 comments on commit 992d374

Please sign in to comment.