Skip to content

Commit

Permalink
tests: general fixes for tests failing in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
tegefaulkes committed Sep 21, 2022
1 parent b074df8 commit 65b8c6f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/PolykeyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,10 +700,10 @@ class PolykeyAgent {
await this.notificationsManager?.stop();
await this.vaultManager?.stop();
await this.discovery?.stop();
await this.taskManager?.stop();
await this.nodeGraph?.stop();
await this.nodeConnectionManager?.stop();
await this.nodeManager?.stop();
await this.taskManager?.stop();
await this.proxy?.stop();
await this.grpcServerAgent?.stop();
await this.grpcServerClient?.stop();
Expand Down
16 changes: 10 additions & 6 deletions src/nodes/NodeConnectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import GRPCClientAgent from '../agent/GRPCClientAgent';
import * as validationUtils from '../validation/utils';
import * as networkUtils from '../network/utils';
import * as nodesPB from '../proto/js/polykey/v1/nodes/nodes_pb';
import { timerStart } from '../utils';
import { timerStart, never } from '../utils';

type ConnectionAndTimer = {
connection: NodeConnection<GRPCClientAgent>;
Expand Down Expand Up @@ -119,7 +119,8 @@ class NodeConnectionManager {
this.nodeManager = nodeManager;
// Adding seed nodes
for (const nodeIdEncoded in this.seedNodes) {
const nodeId = nodesUtils.decodeNodeId(nodeIdEncoded)!;
const nodeId = nodesUtils.decodeNodeId(nodeIdEncoded);
if (nodeId == null) never();
await this.nodeManager.setNode(
nodeId,
this.seedNodes[nodeIdEncoded],
Expand Down Expand Up @@ -224,7 +225,8 @@ class NodeConnectionManager {
const [release, conn] = await acquire();
let caughtError;
try {
return yield* g(conn!);
if (conn == null) never();
return yield* g(conn);
} catch (e) {
caughtError = e;
throw e;
Expand Down Expand Up @@ -701,9 +703,11 @@ class NodeConnectionManager {
*/
@ready(new nodesErrors.ErrorNodeConnectionManagerNotRunning())
public getSeedNodes(): Array<NodeId> {
return Object.keys(this.seedNodes).map(
(nodeIdEncoded) => nodesUtils.decodeNodeId(nodeIdEncoded)!,
);
return Object.keys(this.seedNodes).map((nodeIdEncoded) => {
const nodeId = nodesUtils.decodeNodeId(nodeIdEncoded);
if (nodeId == null) never();
return nodeId;
});
}

/**
Expand Down
20 changes: 15 additions & 5 deletions src/nodes/NodeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ class NodeManager {
host: Host,
port: Port,
) => {
const nodeId = nodesUtils.decodeNodeId(nodeIdEncoded)!;
const nodeId = nodesUtils.decodeNodeId(nodeIdEncoded);
if (nodeId == null) {
this.logger.error(
`pingAndSetNodeHandler received invalid NodeId: ${nodeIdEncoded}`,
);
never();
}
const host_ = await networkUtils.resolveHost(host);
if (
await this.pingNode(nodeId, { host: host_, port }, { signal: ctx.signal })
Expand Down Expand Up @@ -569,7 +575,8 @@ class NodeManager {
// We just add the new node anyway without checking the old one
const oldNodeId = (
await this.nodeGraph.getOldestNode(bucketIndex, 1, tran)
).pop()!;
).pop();
if (oldNodeId == null) never();
this.logger.debug(
`Force was set, removing ${nodesUtils.encodeNodeId(
oldNodeId,
Expand Down Expand Up @@ -1013,10 +1020,13 @@ class NodeManager {
}
}
// Refreshing every bucket above the closest node
let closestNodeInfo = closestNodes.pop()!;
if (this.keyManager.getNodeId().equals(closestNodeInfo[0])) {
let closestNodeInfo = closestNodes.pop();
if (
closestNodeInfo != null &&
this.keyManager.getNodeId().equals(closestNodeInfo[0])
) {
// Skip our nodeId if it exists
closestNodeInfo = closestNodes.pop()!;
closestNodeInfo = closestNodes.pop();
}
let index = this.nodeGraph.nodeIdBits;
if (closestNodeInfo != null) {
Expand Down
3 changes: 3 additions & 0 deletions tests/discovery/Discovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as nodesUtils from '@/nodes/utils';
import * as claimsUtils from '@/claims/utils';
import * as discoveryErrors from '@/discovery/errors';
import * as keysUtils from '@/keys/utils';
import * as grpcUtils from '@/grpc/utils/index';
import * as testNodesUtils from '../nodes/utils';
import TestProvider from '../identities/TestProvider';
import { globalRootKeyPems } from '../fixtures/globalRootKeyPems';
Expand Down Expand Up @@ -59,6 +60,8 @@ describe('Discovery', () => {
let nodeB: PolykeyAgent;
let identityId: IdentityId;
beforeEach(async () => {
// Sets the global GRPC logger to the logger
grpcUtils.setLogger(logger);
dataDir = await fs.promises.mkdtemp(
path.join(os.tmpdir(), 'polykey-test-'),
);
Expand Down

0 comments on commit 65b8c6f

Please sign in to comment.