diff --git a/package.json b/package.json index fc6724e08..19f24c59c 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "istanbul": "^0.4.5", "jsdoc": "^3.4.0", "lolex": "^1.5.2", - "matrix-mock-request": "^1.1.0", + "matrix-mock-request": "^1.2.0", "mocha": "^3.2.0", "mocha-jenkins-reporter": "^0.3.6", "rimraf": "^2.5.4", diff --git a/spec/integ/matrix-client-room-timeline.spec.js b/spec/integ/matrix-client-room-timeline.spec.js index 908324db0..fdc5ea097 100644 --- a/spec/integ/matrix-client-room-timeline.spec.js +++ b/spec/integ/matrix-client-room-timeline.spec.js @@ -252,11 +252,14 @@ describe("MatrixClient room timelines", function() { client.scrollback(room).done(function() { expect(room.timeline.length).toEqual(1); expect(room.oldState.paginationToken).toBe(null); - done(); + + // still have a sync to flush + httpBackend.flush("/sync", 1).then(() => { + done(); + }); }); httpBackend.flush("/messages", 1); - httpBackend.flush("/sync", 1); }); httpBackend.flush("/sync", 1); }); @@ -318,11 +321,14 @@ describe("MatrixClient room timelines", function() { expect(oldMsg.sender.name).toEqual("Old Alice"); const newMsg = room.timeline[3]; expect(newMsg.sender.name).toEqual(userName); - done(); + + // still have a sync to flush + httpBackend.flush("/sync", 1).then(() => { + done(); + }); }); httpBackend.flush("/messages", 1); - httpBackend.flush("/sync", 1); }); httpBackend.flush("/sync", 1); }); @@ -349,11 +355,14 @@ describe("MatrixClient room timelines", function() { expect(room.timeline.length).toEqual(3); expect(room.timeline[0].event).toEqual(sbEvents[1]); expect(room.timeline[1].event).toEqual(sbEvents[0]); - done(); + + // still have a sync to flush + httpBackend.flush("/sync", 1).then(() => { + done(); + }); }); httpBackend.flush("/messages", 1); - httpBackend.flush("/sync", 1); }); httpBackend.flush("/sync", 1); }); @@ -377,9 +386,11 @@ describe("MatrixClient room timelines", function() { expect(room.oldState.paginationToken).toEqual(sbEndTok); }); - httpBackend.flush("/sync", 1); httpBackend.flush("/messages", 1).done(function() { - done(); + // still have a sync to flush + httpBackend.flush("/sync", 1).then(() => { + done(); + }); }); }); httpBackend.flush("/sync", 1); diff --git a/spec/integ/megolm-integ.spec.js b/spec/integ/megolm-integ.spec.js index 05f96a780..9e71ef814 100644 --- a/spec/integ/megolm-integ.spec.js +++ b/spec/integ/megolm-integ.spec.js @@ -554,7 +554,11 @@ describe("megolm", function() { return Promise.all([ aliceTestClient.client.resendEvent(pendingMsg, room), - aliceTestClient.httpBackend.flushAllExpected(), + + // the crypto stuff can take a while, so give the requests a whole second. + aliceTestClient.httpBackend.flushAllExpected({ + timeout: 1000, + }), ]); }); }); @@ -589,7 +593,11 @@ describe("megolm", function() { return Promise.all([ aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'), - aliceTestClient.httpBackend.flushAllExpected(), + + // the crypto stuff can take a while, so give the requests a whole second. + aliceTestClient.httpBackend.flushAllExpected({ + timeout: 1000, + }), ]); }); }); @@ -636,7 +644,11 @@ describe("megolm", function() { return Promise.all([ aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'), - aliceTestClient.httpBackend.flushAllExpected(), + + // the crypto stuff can take a while, so give the requests a whole second. + aliceTestClient.httpBackend.flushAllExpected({ + timeout: 1000, + }), ]); }); }); @@ -705,7 +717,11 @@ describe("megolm", function() { return Promise.all([ aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'), - aliceTestClient.httpBackend.flushAllExpected(), + + // the crypto stuff can take a while, so give the requests a whole second. + aliceTestClient.httpBackend.flushAllExpected({ + timeout: 1000, + }), ]); }).then(function() { console.log('Telling alice to block our device'); @@ -826,7 +842,11 @@ describe("megolm", function() { return Promise.all([ aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'), - aliceTestClient.httpBackend.flushAllExpected(), + + // the crypto stuff can take a while, so give the requests a whole second. + aliceTestClient.httpBackend.flushAllExpected({ + timeout: 1000, + }), ]); }).then(function() { expect(decrypted.type).toEqual('m.room.message'); diff --git a/spec/unit/crypto/algorithms/megolm.spec.js b/spec/unit/crypto/algorithms/megolm.spec.js index de2dc9b02..468cd7645 100644 --- a/spec/unit/crypto/algorithms/megolm.spec.js +++ b/spec/unit/crypto/algorithms/megolm.spec.js @@ -124,19 +124,23 @@ describe("MegolmDecryption", function() { // set up some pre-conditions for the share call const deviceInfo = {}; mockCrypto.getStoredDevice.andReturn(deviceInfo); - mockOlmLib.ensureOlmSessionsForDevices.andReturn( - Promise.resolve({'@alice:foo': {'alidevice': { - sessionId: 'alisession', - }}}), - ); - mockBaseApis.sendToDevice = expect.createSpy(); + const awaitEnsureSessions = new Promise((res, rej) => { + mockOlmLib.ensureOlmSessionsForDevices.andCall(() => { + res(); + return Promise.resolve({'@alice:foo': {'alidevice': { + sessionId: 'alisession', + }}}); + }); + }); + + mockBaseApis.sendToDevice = expect.createSpy(); // do the share megolmDecryption.shareKeysWithDevice(keyRequest); // it's asynchronous, so we have to wait a bit - return Promise.delay(1).then(() => { + return awaitEnsureSessions.then(() => { // check that it called encryptMessageForDevice with // appropriate args. expect(mockOlmLib.encryptMessageForDevice.calls.length)