Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Test resolve
  • Loading branch information
addievo committed Sep 6, 2023
1 parent 137f93f commit c6662b3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 37 deletions.
26 changes: 13 additions & 13 deletions tests/rpc/RPC.test.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import type { ContainerType, JSONRPCRequest } from '../../../Polykey/src/rpc/types';
import type { ContainerType, JSONRPCRequest } from '../../src/types';
import type { ReadableStream } from 'stream/web';
import type { JSONValue } from '../../../Polykey/src/types';
import type { JSONValue } from '../../src/types';
import { TransformStream } from 'stream/web';
import { fc, testProp } from '@fast-check/jest';
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
import * as utils from '../../../Polykey/src/utils';
import RPCServer from '../../../Polykey/src/rpc/RPCServer';
import RPCClient from '../../../Polykey/src/rpc/RPCClient';
import * as rpcTestUtils from './utils';
import * as utils from '../../src/utils';
import RPCServer from '../../src/RPCServer';
import RPCClient from '../../src/RPCClient';
import {
ClientHandler,
DuplexHandler,
RawHandler,
ServerHandler,
UnaryHandler,
} from '../../../Polykey/src/rpc/handlers';
} from '../../src/handlers';
import {
ClientCaller,
DuplexCaller,
RawCaller,
ServerCaller,
UnaryCaller,
} from '../../../Polykey/src/rpc/callers';
import * as rpcErrors from '../../../Polykey/src/rpc/errors';
import * as rpcUtilsMiddleware from '../../../Polykey/src/rpc/utils/middleware';
import * as rpcTestUtils from './utils';
} from '../../src/callers';
import * as rpcErrors from '../../src/errors';
import * as rpcUtilsMiddleware from '../../src/utils/middleware';

describe('RPC', () => {
const logger = new Logger(`RPC Test`, LogLevel.WARN, [new StreamHandler()]);
Expand Down Expand Up @@ -169,7 +169,7 @@ describe('RPC', () => {
rpcClient.methods.testMethod({
hello: 'world',
}),
).rejects.toThrow(rpcErrors.ErrorPolykeyRemote);
).rejects.toThrow(rpcErrors.ErrorRPCRemote);

await rpcServer.destroy();
await rpcClient.destroy();
Expand Down Expand Up @@ -420,7 +420,7 @@ describe('RPC', () => {
});

const callProm = rpcClient.methods.testMethod(value);
await expect(callProm).rejects.toThrow(rpcErrors.ErrorPolykeyRemote);
await expect(callProm).rejects.toThrow(rpcErrors.ErrorRPCRemote);
await expect(
callProm.catch((e) => {
throw e.cause;
Expand Down Expand Up @@ -476,7 +476,7 @@ describe('RPC', () => {
});

const callProm = rpcClient.methods.testMethod(value);
await expect(callProm).rejects.toThrow(rpcErrors.ErrorPolykeyRemote);
await expect(callProm).rejects.toThrow(rpcErrors.ErrorRPCRemote);
await expect(
callProm.catch((e) => {
throw e.cause;
Expand Down
25 changes: 13 additions & 12 deletions tests/rpc/RPCClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import type { ContextTimed } from '@matrixai/contexts';
import type { JSONValue } from '../../../Polykey/src/types';
import type { JSONValue } from '../../src/types';
import type {
JSONRPCRequest,
JSONRPCRequestMessage,
JSONRPCResponse,
JSONRPCResponseResult,
RPCStream,
} from '../../../Polykey/src/rpc/types';
} from '../../src/types';
import { TransformStream, ReadableStream } from 'stream/web';
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
import { testProp, fc } from '@fast-check/jest';
import RPCClient from '../../../Polykey/src/rpc/RPCClient';
import RPCServer from '../../../Polykey/src/rpc/RPCServer';
import * as rpcErrors from '../../../Polykey/src/rpc/errors';
import * as rpcTestUtils from './utils';
import RPCClient from '../../src/RPCClient';
import RPCServer from '../../src/RPCServer';
import * as rpcErrors from '../../src/errors';
import {
ClientCaller,
DuplexCaller,
RawCaller,
ServerCaller,
UnaryCaller,
} from '../../../Polykey/src/rpc/callers';
import * as rpcUtilsMiddleware from '../../../Polykey/src/rpc/utils/middleware';
import { promise, sleep } from '../../../Polykey/src/utils';
import * as rpcTestUtils from './utils';
} from '../../src/callers';
import * as rpcUtilsMiddleware from '../../src/utils/middleware';
import { promise, sleep } from '../../src/utils';
import { ErrorRPCRemote } from '../../src/errors';

describe(`${RPCClient.name}`, () => {
const logger = new Logger(`${RPCServer.name} Test`, LogLevel.WARN, [
Expand Down Expand Up @@ -285,7 +286,7 @@ describe(`${RPCClient.name}`, () => {
// Only consume
}
})();
await expect(callProm).rejects.toThrow(rpcErrors.ErrorPolykeyRemote);
await expect(callProm).rejects.toThrow(rpcErrors.ErrorRPCRemote);
await outputResult;
await rpcClient.destroy();
},
Expand Down Expand Up @@ -324,7 +325,7 @@ describe(`${RPCClient.name}`, () => {
// Only consume
}
})();
await expect(callProm).rejects.toThrow(rpcErrors.ErrorPolykeyRemote);
await expect(callProm).rejects.toThrow(rpcErrors.ErrorRPCRemote);
await outputResult;
await rpcClient.destroy();
},
Expand Down Expand Up @@ -366,7 +367,7 @@ describe(`${RPCClient.name}`, () => {
// Only consume
}
})();
await expect(callProm).rejects.toThrow(rpcErrors.ErrorPolykeyRemote);
await expect(callProm).rejects.toThrow(rpcErrors.ErrorRPCRemote);
await outputResult;
await rpcClient.destroy();
},
Expand Down
22 changes: 10 additions & 12 deletions tests/rpc/RPCServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,25 @@ import type {
JSONRPCResponse,
JSONRPCResponseError,
RPCStream,
} from '../../../Polykey/src/rpc/types';
import type { JSONValue } from '../../../Polykey/src/types';
import type { NodeId } from '../../../Polykey/src/ids';
import type { RPCErrorEvent } from '../../../Polykey/src/rpc/events';
} from '../../src/types';
import type { JSONValue } from '../../src/types';
import type { RPCErrorEvent } from '../../src/events';
import { ReadableStream, TransformStream, WritableStream } from 'stream/web';
import { fc, testProp } from '@fast-check/jest';
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
import RPCServer from '../../../Polykey/src/rpc/RPCServer';
import * as rpcErrors from '../../../Polykey/src/rpc/errors';
import * as rpcUtils from '../../../Polykey/src/rpc/utils';
import * as rpcTestUtils from './utils';
import RPCServer from '../../src/RPCServer';
import * as rpcErrors from '../../src/errors';
import * as rpcUtils from '../../src/utils';
import {
ClientHandler,
DuplexHandler,
RawHandler,
ServerHandler,
UnaryHandler,
} from '../../../Polykey/src/rpc/handlers';
import * as rpcUtilsMiddleware from '../../../Polykey/src/rpc/utils/middleware';
import { promise, sleep } from '../../../Polykey/src/utils';
import * as rpcTestUtils from './utils';
} from '../../src/handlers';
import * as rpcUtilsMiddleware from '../../src/utils/middleware';
import { promise, sleep } from '../../src/utils';

describe(`${RPCServer.name}`, () => {
const logger = new Logger(`${RPCServer.name} Test`, LogLevel.WARN, [
Expand Down Expand Up @@ -272,7 +271,6 @@ describe(`${RPCServer.name}`, () => {
localPort: 12341,
remoteCertificates: [],
remoteHost: 'hostA',
remoteNodeId: 'asd' as unknown as NodeId,
remotePort: 12341,
};
let handledMeta;
Expand Down

0 comments on commit c6662b3

Please sign in to comment.