diff --git a/spec/integ/matrix-client-retrying.spec.js b/spec/integ/matrix-client-retrying.spec.js index 56a9d4db6..1c3b95d2a 100644 --- a/spec/integ/matrix-client-retrying.spec.js +++ b/spec/integ/matrix-client-retrying.spec.js @@ -1,5 +1,7 @@ "use strict"; import 'source-map-support/register'; +import Promise from 'bluebird'; + const sdk = require("../.."); const HttpBackend = require("matrix-mock-request"); const utils = require("../test-utils"); @@ -52,15 +54,20 @@ describe("MatrixClient retrying", function() { }); - it("should mark events as EventStatus.CANCELLED when cancelled", function(done) { + it("should mark events as EventStatus.CANCELLED when cancelled", function() { // send a couple of events; the second will be queued - client.sendMessage(roomId, "m1").then(function(ev) { - expect(ev).toEqual(ev1); - }); - client.sendMessage(roomId, "m2").then(function(ev) { - expect(ev).toEqual(ev2); + const p1 = client.sendMessage(roomId, "m1").then(function(ev) { + // we expect the first message to fail + throw new Error('Message 1 unexpectedly sent successfully'); + }, (e) => { + // this is expected }); + // XXX: it turns out that the promise returned by this message + // never gets resolved. + // https://github.com/matrix-org/matrix-js-sdk/issues/496 + client.sendMessage(roomId, "m2"); + // both events should be in the timeline at this point const tl = room.getLiveTimeline().getEvents(); expect(tl.length).toEqual(2); @@ -86,7 +93,7 @@ describe("MatrixClient retrying", function() { }).toThrow(); }).respond(400); // fail the first message - httpBackend.flush().then(function() { + const p3 = httpBackend.flush().then(function() { expect(ev1.status).toEqual(EventStatus.NOT_SENT); expect(tl.length).toEqual(1); @@ -94,7 +101,9 @@ describe("MatrixClient retrying", function() { client.cancelPendingEvent(ev1); expect(ev1.status).toEqual(EventStatus.CANCELLED); expect(tl.length).toEqual(0); - }).nodeify(done); + }); + + return Promise.all([p1, p3]); }); describe("resending", function() { diff --git a/src/scheduler.js b/src/scheduler.js index 75ec5850c..bb7853239 100644 --- a/src/scheduler.js +++ b/src/scheduler.js @@ -83,6 +83,8 @@ MatrixScheduler.prototype.removeEventFromQueue = function(event) { let removed = false; utils.removeElement(this._queues[name], function(element) { if (element.event.getId() === event.getId()) { + // XXX we should probably reject the promise? + // https://github.com/matrix-org/matrix-js-sdk/issues/496 removed = true; return true; }