Unverified Commit c39e688c authored by chicm-ms's avatar chicm-ms Committed by GitHub
Browse files

Fix IPC unit test (#511)

* Fix IPC unit test

* updates
parent 26cef96c
...@@ -26,12 +26,14 @@ export namespace NNIErrorNames { ...@@ -26,12 +26,14 @@ export namespace NNIErrorNames {
} }
export class NNIError extends Error { export class NNIError extends Error {
public cause!: Error | undefined;
constructor (name: string, message: string, err?: Error) { constructor (name: string, message: string, err?: Error) {
super(message); super(message);
this.name = name; this.name = name;
if (err !== undefined) { if (err !== undefined) {
this.stack = err.stack; this.stack = err.stack;
} }
this.cause = err;
} }
} }
......
...@@ -103,7 +103,7 @@ class IpcInterface { ...@@ -103,7 +103,7 @@ class IpcInterface {
try { try {
const data: Buffer = encodeCommand(commandType, content); const data: Buffer = encodeCommand(commandType, content);
if (!this.outgoingStream.write(data)) { if (!this.outgoingStream.write(data)) {
this.logger.error('Commands jammed in buffer!'); this.logger.warning('Commands jammed in buffer!');
} }
} catch (err) { } catch (err) {
throw new NNIError('Dispatcher Error', `Dispatcher Error: ${err.message}`, err); throw new NNIError('Dispatcher Error', `Dispatcher Error: ${err.message}`, err);
......
...@@ -25,6 +25,7 @@ import { Deferred } from 'ts-deferred'; ...@@ -25,6 +25,7 @@ import { Deferred } from 'ts-deferred';
import { cleanupUnitTest, prepareUnitTest } from '../../common/utils'; import { cleanupUnitTest, prepareUnitTest } from '../../common/utils';
import * as CommandType from '../commands'; import * as CommandType from '../commands';
import { createDispatcherInterface, IpcInterface } from '../ipcInterface'; import { createDispatcherInterface, IpcInterface } from '../ipcInterface';
import { NNIError } from '../../common/errors';
let sentCommands: {[key: string]: string}[] = []; let sentCommands: {[key: string]: string}[] = [];
const receivedCommands: {[key: string]: string}[] = []; const receivedCommands: {[key: string]: string}[] = [];
...@@ -105,8 +106,13 @@ describe('core/protocol', (): void => { ...@@ -105,8 +106,13 @@ describe('core/protocol', (): void => {
}); });
it('sendCommand() should throw on too long command', (): void => { it('sendCommand() should throw on too long command', (): void => {
assert.equal((<Error>commandTooLong).name, 'RangeError'); if (commandTooLong === undefined) {
assert.equal((<Error>commandTooLong).message, 'Command too long'); assert.fail('Should throw error')
} else {
const err: Error | undefined = (<NNIError>commandTooLong).cause;
assert(err && err.name === 'RangeError');
assert(err && err.message === 'Command too long');
}
}); });
it('sendCommand() should throw on wrong command type', (): void => { it('sendCommand() should throw on wrong command type', (): void => {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment