1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-09 10:22:46 +03:00

Merge pull request #499 from matrix-org/rav/omfg_when_will_it_end

Yet more js-sdk test deflakification
This commit is contained in:
Richard van der Hoff
2017-07-17 11:57:05 +01:00
committed by GitHub
4 changed files with 56 additions and 21 deletions

View File

@@ -69,7 +69,7 @@
"istanbul": "^0.4.5", "istanbul": "^0.4.5",
"jsdoc": "^3.4.0", "jsdoc": "^3.4.0",
"lolex": "^1.5.2", "lolex": "^1.5.2",
"matrix-mock-request": "^1.1.0", "matrix-mock-request": "^1.2.0",
"mocha": "^3.2.0", "mocha": "^3.2.0",
"mocha-jenkins-reporter": "^0.3.6", "mocha-jenkins-reporter": "^0.3.6",
"rimraf": "^2.5.4", "rimraf": "^2.5.4",

View File

@@ -252,11 +252,14 @@ describe("MatrixClient room timelines", function() {
client.scrollback(room).done(function() { client.scrollback(room).done(function() {
expect(room.timeline.length).toEqual(1); expect(room.timeline.length).toEqual(1);
expect(room.oldState.paginationToken).toBe(null); 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("/messages", 1);
httpBackend.flush("/sync", 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"); expect(oldMsg.sender.name).toEqual("Old Alice");
const newMsg = room.timeline[3]; const newMsg = room.timeline[3];
expect(newMsg.sender.name).toEqual(userName); 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("/messages", 1);
httpBackend.flush("/sync", 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.length).toEqual(3);
expect(room.timeline[0].event).toEqual(sbEvents[1]); expect(room.timeline[0].event).toEqual(sbEvents[1]);
expect(room.timeline[1].event).toEqual(sbEvents[0]); 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("/messages", 1);
httpBackend.flush("/sync", 1);
}); });
httpBackend.flush("/sync", 1); httpBackend.flush("/sync", 1);
}); });
@@ -377,9 +386,11 @@ describe("MatrixClient room timelines", function() {
expect(room.oldState.paginationToken).toEqual(sbEndTok); expect(room.oldState.paginationToken).toEqual(sbEndTok);
}); });
httpBackend.flush("/sync", 1);
httpBackend.flush("/messages", 1).done(function() { httpBackend.flush("/messages", 1).done(function() {
done(); // still have a sync to flush
httpBackend.flush("/sync", 1).then(() => {
done();
});
}); });
}); });
httpBackend.flush("/sync", 1); httpBackend.flush("/sync", 1);

View File

@@ -554,7 +554,11 @@ describe("megolm", function() {
return Promise.all([ return Promise.all([
aliceTestClient.client.resendEvent(pendingMsg, room), 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([ return Promise.all([
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'), 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([ return Promise.all([
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'), 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([ return Promise.all([
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'), 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() { }).then(function() {
console.log('Telling alice to block our device'); console.log('Telling alice to block our device');
@@ -826,7 +842,11 @@ describe("megolm", function() {
return Promise.all([ return Promise.all([
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'), 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() { }).then(function() {
expect(decrypted.type).toEqual('m.room.message'); expect(decrypted.type).toEqual('m.room.message');

View File

@@ -124,19 +124,23 @@ describe("MegolmDecryption", function() {
// set up some pre-conditions for the share call // set up some pre-conditions for the share call
const deviceInfo = {}; const deviceInfo = {};
mockCrypto.getStoredDevice.andReturn(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 // do the share
megolmDecryption.shareKeysWithDevice(keyRequest); megolmDecryption.shareKeysWithDevice(keyRequest);
// it's asynchronous, so we have to wait a bit // it's asynchronous, so we have to wait a bit
return Promise.delay(1).then(() => { return awaitEnsureSessions.then(() => {
// check that it called encryptMessageForDevice with // check that it called encryptMessageForDevice with
// appropriate args. // appropriate args.
expect(mockOlmLib.encryptMessageForDevice.calls.length) expect(mockOlmLib.encryptMessageForDevice.calls.length)