diff options
| author | Erik Larkö <erik@mullvad.net> | 2017-05-28 18:16:53 +0200 |
|---|---|---|
| committer | Erik Larkö <erik@mullvad.net> | 2017-05-28 18:16:53 +0200 |
| commit | 6daf4bb8d27251a298558f1823d5d198d7c0538e (patch) | |
| tree | ef0f5beb0ce8bc64c0366e893d17cdb23911cf49 | |
| parent | 34a54cdb1bf8be6ba9a33378626d42b93ec25574 (diff) | |
| parent | 05637b51945dbc9cd9d09fc191ef84126a1f770e (diff) | |
| download | mullvadvpn-6daf4bb8d27251a298558f1823d5d198d7c0538e.tar.xz mullvadvpn-6daf4bb8d27251a298558f1823d5d198d7c0538e.zip | |
Merge branch 'ipc-timeout-test'
| -rw-r--r-- | app/lib/jsonrpc-ws-ipc.js | 8 | ||||
| -rw-r--r-- | test/ipc.spec.js | 11 |
2 files changed, 18 insertions, 1 deletions
diff --git a/app/lib/jsonrpc-ws-ipc.js b/app/lib/jsonrpc-ws-ipc.js index f2b54b38da..f3850c430c 100644 --- a/app/lib/jsonrpc-ws-ipc.js +++ b/app/lib/jsonrpc-ws-ipc.js @@ -56,6 +56,7 @@ export default class Ipc { _websocket: WebSocket; _backoff: ReconnectionBackoff; _websocketFactory: (string) => WebSocket; + _sendTimeoutMillis: number; constructor(connectionString: string, websocketFactory: ?(string)=>WebSocket) { this._connectionString = connectionString; @@ -63,11 +64,16 @@ export default class Ipc { this._unansweredRequests = {}; this._subscriptions = {}; this._websocketFactory = websocketFactory || (connectionString => new WebSocket(connectionString)); + this._sendTimeoutMillis = DEFAULT_TIMEOUT_MILLIS; this._backoff = new ReconnectionBackoff(); this._reconnect(); } + setSendTimeout(millis: number) { + this._sendTimeoutMillis = millis; + } + on(event: string, listener: (any) => void) { // We're currently not actually using the event parameter. // This is because we aren't sure if the backend will use @@ -106,7 +112,7 @@ export default class Ipc { const id = uuid.v4(); const jsonrpcMessage = jsonrpc.request(id, action, data); - const timeout = setTimeout(() => this._onTimeout(id), DEFAULT_TIMEOUT_MILLIS); + const timeout = setTimeout(() => this._onTimeout(id), this._sendTimeoutMillis); this._unansweredRequests[id] = { resolve: resolve, reject: reject, diff --git a/test/ipc.spec.js b/test/ipc.spec.js index 07421ce839..43a17b4911 100644 --- a/test/ipc.spec.js +++ b/test/ipc.spec.js @@ -58,6 +58,17 @@ describe('The IPC server', () => { return Promise.all([message, decoy]); }); + + it('should timeout if no response is returned', () => { + const { ipc } = setupIpc(); + + ipc.setSendTimeout(1); + return ipc.send('a message') + .catch((e) => { + expect(e.name).to.equal('TimeOutError'); + expect(e.message).to.contain('timed out'); + }); + }); }); function mockWebsocket() { |
