1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-07 23:02:56 +03:00

Clean up test shutdown

Make sure that the integration tests actually kill off all of their timers, so
that jasmine exits cleanly.

This probably also fixes https://github.com/vector-im/vector-web/issues/1365.
This commit is contained in:
Richard van der Hoff
2016-04-14 12:01:23 +01:00
parent 0282021e09
commit 3404751eb9
8 changed files with 46 additions and 16 deletions

View File

@@ -419,6 +419,10 @@ SyncApi.prototype.stop = function() {
} }
this._running = false; this._running = false;
if (this._currentSyncRequest) { this._currentSyncRequest.abort(); } if (this._currentSyncRequest) { this._currentSyncRequest.abort(); }
if (this._keepAliveTimer) {
clearTimeout(this._keepAliveTimer);
this._keepAliveTimer = null;
}
}; };
/** /**

View File

@@ -4,8 +4,8 @@
"description": "Matrix Client-Server SDK for Javascript", "description": "Matrix Client-Server SDK for Javascript",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "istanbul cover --report cobertura --config .istanbul.yml -i \"lib/**/*.js\" jasmine-node -- spec --verbose --junitreport --forceexit --captureExceptions", "test": "istanbul cover --report cobertura --config .istanbul.yml -i \"lib/**/*.js\" jasmine-node -- spec --verbose --junitreport --captureExceptions",
"check": "jasmine-node spec --verbose --junitreport --forceexit --captureExceptions", "check": "jasmine-node spec --verbose --junitreport --captureExceptions",
"gendoc": "jsdoc -r lib -P package.json -R README.md -d .jsdoc", "gendoc": "jsdoc -r lib -P package.json -R README.md -d .jsdoc",
"build": "jshint -c .jshint lib/ && browserify browser-index.js -o dist/browser-matrix-dev.js --ignore-missing", "build": "jshint -c .jshint lib/ && browserify browser-index.js -o dist/browser-matrix-dev.js --ignore-missing",
"watch": "watchify browser-index.js -o dist/browser-matrix-dev.js -v", "watch": "watchify browser-index.js -o dist/browser-matrix-dev.js -v",

View File

@@ -24,6 +24,7 @@ describe("MatrixClient events", function() {
afterEach(function() { afterEach(function() {
httpBackend.verifyNoOutstandingExpectation(); httpBackend.verifyNoOutstandingExpectation();
client.stopClient();
}); });
describe("emissions", function() { describe("emissions", function() {

View File

@@ -97,6 +97,7 @@ function startClient(httpBackend, client) {
describe("getEventTimeline support", function() { describe("getEventTimeline support", function() {
var httpBackend; var httpBackend;
var client;
beforeEach(function() { beforeEach(function() {
utils.beforeEach(this); utils.beforeEach(this);
@@ -104,8 +105,14 @@ describe("getEventTimeline support", function() {
sdk.request(httpBackend.requestFn); sdk.request(httpBackend.requestFn);
}); });
afterEach(function() {
if (client) {
client.stopClient();
}
});
it("timeline support must be enabled to work", function(done) { it("timeline support must be enabled to work", function(done) {
var client = sdk.createClient({ client = sdk.createClient({
baseUrl: baseUrl, baseUrl: baseUrl,
userId: userId, userId: userId,
accessToken: accessToken, accessToken: accessToken,
@@ -120,7 +127,7 @@ describe("getEventTimeline support", function() {
}); });
it("timeline support works when enabled", function(done) { it("timeline support works when enabled", function(done) {
var client = sdk.createClient({ client = sdk.createClient({
baseUrl: baseUrl, baseUrl: baseUrl,
userId: userId, userId: userId,
accessToken: accessToken, accessToken: accessToken,
@@ -141,7 +148,7 @@ describe("getEventTimeline support", function() {
it("scrollback should be able to scroll back to before a gappy /sync", it("scrollback should be able to scroll back to before a gappy /sync",
function(done) { function(done) {
// need a client with timelineSupport disabled to make this work // need a client with timelineSupport disabled to make this work
var client = sdk.createClient({ client = sdk.createClient({
baseUrl: baseUrl, baseUrl: baseUrl,
userId: userId, userId: userId,
accessToken: accessToken, accessToken: accessToken,
@@ -229,6 +236,7 @@ describe("MatrixClient event timelines", function() {
afterEach(function() { afterEach(function() {
httpBackend.verifyNoOutstandingExpectation(); httpBackend.verifyNoOutstandingExpectation();
client.stopClient();
}); });
describe("getEventTimeline", function() { describe("getEventTimeline", function() {

View File

@@ -73,6 +73,10 @@ describe("MatrixClient opts", function() {
}); });
}); });
afterEach(function() {
client.stopClient();
});
it("should be able to send messages", function(done) { it("should be able to send messages", function(done) {
var eventId = "$flibble:wibble"; var eventId = "$flibble:wibble";
httpBackend.when("PUT", "/txn1").respond(200, { httpBackend.when("PUT", "/txn1").respond(200, {

View File

@@ -126,6 +126,7 @@ describe("MatrixClient room timelines", function() {
afterEach(function() { afterEach(function() {
httpBackend.verifyNoOutstandingExpectation(); httpBackend.verifyNoOutstandingExpectation();
client.stopClient();
}); });
describe("local echo events", function() { describe("local echo events", function() {
@@ -391,16 +392,16 @@ describe("MatrixClient room timelines", function() {
}); });
httpBackend.flush("/messages", 1); httpBackend.flush("/messages", 1);
httpBackend.flush("/sync", 1).done(function() { httpBackend.flush("/sync", 1).then(function() {
expect(index).toEqual(2); expect(index).toEqual(2);
expect(room.timeline[room.timeline.length - 1].event).toEqual( expect(room.timeline.length).toEqual(3);
expect(room.timeline[2].event).toEqual(
eventData[1] eventData[1]
); );
expect(room.timeline[room.timeline.length - 2].event).toEqual( expect(room.timeline[1].event).toEqual(
eventData[0] eventData[0]
); );
done(); }).catch(utils.failTest).done(done);
});
}); });
httpBackend.flush("/sync", 1); httpBackend.flush("/sync", 1);
}); });
@@ -419,13 +420,12 @@ describe("MatrixClient room timelines", function() {
client.on("sync", function(state) { client.on("sync", function(state) {
if (state !== "PREPARED") { return; } if (state !== "PREPARED") { return; }
var room = client.getRoom(roomId); var room = client.getRoom(roomId);
httpBackend.flush("/sync", 1).done(function() { httpBackend.flush("/sync", 1).then(function() {
var preNameEvent = room.timeline[room.timeline.length - 3]; var preNameEvent = room.timeline[room.timeline.length - 3];
var postNameEvent = room.timeline[room.timeline.length - 1]; var postNameEvent = room.timeline[room.timeline.length - 1];
expect(preNameEvent.sender.name).toEqual(userName); expect(preNameEvent.sender.name).toEqual(userName);
expect(postNameEvent.sender.name).toEqual("New Name"); expect(postNameEvent.sender.name).toEqual("New Name");
done(); }).catch(utils.failTest).done(done);
});
}); });
httpBackend.flush("/sync", 1); httpBackend.flush("/sync", 1);
}); });
@@ -487,7 +487,7 @@ describe("MatrixClient room timelines", function() {
client.on("sync", function(state) { client.on("sync", function(state) {
if (state !== "PREPARED") { return; } if (state !== "PREPARED") { return; }
var room = client.getRoom(roomId); var room = client.getRoom(roomId);
httpBackend.flush("/sync", 1).done(function() { httpBackend.flush("/sync", 1).then(function() {
expect(room.currentState.getMembers().length).toEqual(4); expect(room.currentState.getMembers().length).toEqual(4);
expect(room.currentState.getMember(userC).name).toEqual("C"); expect(room.currentState.getMember(userC).name).toEqual("C");
expect(room.currentState.getMember(userC).membership).toEqual( expect(room.currentState.getMember(userC).membership).toEqual(
@@ -497,8 +497,7 @@ describe("MatrixClient room timelines", function() {
expect(room.currentState.getMember(userD).membership).toEqual( expect(room.currentState.getMember(userD).membership).toEqual(
"invite" "invite"
); );
done(); }).catch(utils.failTest).done(done);
});
}); });
httpBackend.flush("/sync", 1); httpBackend.flush("/sync", 1);
}); });

View File

@@ -32,6 +32,7 @@ describe("MatrixClient syncing", function() {
afterEach(function() { afterEach(function() {
httpBackend.verifyNoOutstandingExpectation(); httpBackend.verifyNoOutstandingExpectation();
client.stopClient();
}); });
describe("startClient", function() { describe("startClient", function() {

View File

@@ -15,6 +15,19 @@ function HttpBackend() {
realReq.callback = callback; realReq.callback = callback;
console.log("HTTP backend received request: %s %s", opts.method, opts.uri); console.log("HTTP backend received request: %s %s", opts.method, opts.uri);
self.requests.push(realReq); self.requests.push(realReq);
var abort = function() {
var idx = self.requests.indexOf(realReq);
if (idx >= 0) {
console.log("Aborting HTTP request: %s %s", opts.method,
opts.uri);
self.requests.splice(idx, 1);
realReq.callback("aborted");
}
}
return {
abort: abort
};
}; };
} }
HttpBackend.prototype = { HttpBackend.prototype = {