Skip to content

Commit

Permalink
tests: added test for expected timeout delay
Browse files Browse the repository at this point in the history
  • Loading branch information
tegefaulkes committed Oct 7, 2022
1 parent 713f835 commit 69c0ffe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
25 changes: 24 additions & 1 deletion tests/nodes/NodeConnection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Sigchain from '@/sigchain/Sigchain';
import NotificationsManager from '@/notifications/NotificationsManager';
import * as nodesErrors from '@/nodes/errors';
import * as networkErrors from '@/network/errors';
import { poll, promise, promisify } from '@/utils';
import { poll, promise, promisify, sleep } from '@/utils';
import PolykeyAgent from '@/PolykeyAgent';
import * as utilsPB from '@/proto/js/polykey/v1/utils/utils_pb';
import * as GRPCErrors from '@/grpc/errors';
Expand Down Expand Up @@ -555,6 +555,29 @@ describe(`${NodeConnection.name} test`, () => {
),
).rejects.toThrow(nodesErrors.ErrorNodeConnectionTimeout);
});
test('Times out after expected delay', async () => {
let timedOut = false;
const connProm = NodeConnection.createNodeConnection(
{
targetNodeId: targetNodeId,
targetHost: '128.0.0.1' as Host,
targetPort: 12345 as Port,
proxy: clientProxy,
keyManager: clientKeyManager,
nodeConnectionManager: dummyNodeConnectionManager,
destroyCallback,
logger: logger,
clientFactory: (args) => GRPCClientAgent.createGRPCClientAgent(args),
},
{ timer: new Timer({ delay: 1000 }) },
).catch(() => (timedOut = true));
expect(timedOut).toBeFalse();
await sleep(500);
expect(timedOut).toBeFalse();
await sleep(1000);
expect(timedOut).toBeTrue();
await connProm;
});
test('getRootCertChain', async () => {
let nodeConnection: NodeConnection<GRPCClientAgent> | undefined;
try {
Expand Down
2 changes: 0 additions & 2 deletions tests/nodes/NodeConnectionManager.general.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,6 @@ describe(`${NodeConnectionManager.name} general test`, () => {
},
globalThis.polykeyStartupTimeout,
);
// FIXME: This is a know failure due to connection deadline bug,
// disabling for now
test(
'cannot find node (contacts remote node)',
async () => {
Expand Down

0 comments on commit 69c0ffe

Please sign in to comment.