From 88b39f4b672e06f1dd1edff1e6049f0e36b26d91 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 25 Oct 2018 19:00:03 +0100 Subject: [PATCH] Stop devicelist when client is stopped To avoid the devicelist trying to save after the client has been stopped Hopefully will fix random test failures on node 11. --- spec/unit/crypto/DeviceList.spec.js | 13 ++++++++++++- src/crypto/DeviceList.js | 6 ++++++ src/crypto/index.js | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/spec/unit/crypto/DeviceList.spec.js b/spec/unit/crypto/DeviceList.spec.js index 870e40bbc..5a442d81b 100644 --- a/spec/unit/crypto/DeviceList.spec.js +++ b/spec/unit/crypto/DeviceList.spec.js @@ -59,16 +59,25 @@ describe('DeviceList', function() { let downloadSpy; let sessionStore; let cryptoStore; + let deviceLists = []; beforeEach(function() { testUtils.beforeEach(this); // eslint-disable-line no-invalid-this + deviceLists = []; + downloadSpy = expect.createSpy(); const mockStorage = new MockStorageApi(); sessionStore = new WebStorageSessionStore(mockStorage); cryptoStore = new MemoryCryptoStore(); }); + afterEach(function() { + for (const dl of deviceLists) { + dl.stop(); + } + }); + function createTestDeviceList() { const baseApis = { downloadKeysForUsers: downloadSpy, @@ -76,7 +85,9 @@ describe('DeviceList', function() { const mockOlm = { verifySignature: function(key, message, signature) {}, }; - return new DeviceList(baseApis, cryptoStore, sessionStore, mockOlm); + const dl = new DeviceList(baseApis, cryptoStore, sessionStore, mockOlm); + deviceLists.push(dl); + return dl; } it("should successfully download and store device keys", function() { diff --git a/src/crypto/DeviceList.js b/src/crypto/DeviceList.js index f86c9ff99..a9f62b138 100644 --- a/src/crypto/DeviceList.js +++ b/src/crypto/DeviceList.js @@ -146,6 +146,12 @@ export default class DeviceList { } } + stop() { + if (this._saveTimer !== null) { + clearTimeout(this._saveTimer); + } + } + /** * Save the device tracking state to storage, if any changes are * pending other than updating the sync token diff --git a/src/crypto/index.js b/src/crypto/index.js index 64b73164d..082f6d2c9 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -221,6 +221,7 @@ Crypto.prototype.start = function() { /** Stop background processes related to crypto */ Crypto.prototype.stop = function() { this._outgoingRoomKeyRequestManager.stop(); + this._deviceList.stop(); }; /**