You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
Fix racy 'matrixclient retrying' test
when a message send fails, the promise returned by `sendMessage` is rejected. Until we switched to bluebird, the rejection was happily being swallowed, but with bluebird, there's a better chance of the unhandled rejection being caught by the runtime and mocha and failing the test.
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
import 'source-map-support/register';
|
import 'source-map-support/register';
|
||||||
|
import Promise from 'bluebird';
|
||||||
|
|
||||||
const sdk = require("../..");
|
const sdk = require("../..");
|
||||||
const HttpBackend = require("matrix-mock-request");
|
const HttpBackend = require("matrix-mock-request");
|
||||||
const utils = require("../test-utils");
|
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
|
// send a couple of events; the second will be queued
|
||||||
client.sendMessage(roomId, "m1").then(function(ev) {
|
const p1 = client.sendMessage(roomId, "m1").then(function(ev) {
|
||||||
expect(ev).toEqual(ev1);
|
// we expect the first message to fail
|
||||||
});
|
throw new Error('Message 1 unexpectedly sent successfully');
|
||||||
client.sendMessage(roomId, "m2").then(function(ev) {
|
}, (e) => {
|
||||||
expect(ev).toEqual(ev2);
|
// 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
|
// both events should be in the timeline at this point
|
||||||
const tl = room.getLiveTimeline().getEvents();
|
const tl = room.getLiveTimeline().getEvents();
|
||||||
expect(tl.length).toEqual(2);
|
expect(tl.length).toEqual(2);
|
||||||
@@ -86,7 +93,7 @@ describe("MatrixClient retrying", function() {
|
|||||||
}).toThrow();
|
}).toThrow();
|
||||||
}).respond(400); // fail the first message
|
}).respond(400); // fail the first message
|
||||||
|
|
||||||
httpBackend.flush().then(function() {
|
const p3 = httpBackend.flush().then(function() {
|
||||||
expect(ev1.status).toEqual(EventStatus.NOT_SENT);
|
expect(ev1.status).toEqual(EventStatus.NOT_SENT);
|
||||||
expect(tl.length).toEqual(1);
|
expect(tl.length).toEqual(1);
|
||||||
|
|
||||||
@@ -94,7 +101,9 @@ describe("MatrixClient retrying", function() {
|
|||||||
client.cancelPendingEvent(ev1);
|
client.cancelPendingEvent(ev1);
|
||||||
expect(ev1.status).toEqual(EventStatus.CANCELLED);
|
expect(ev1.status).toEqual(EventStatus.CANCELLED);
|
||||||
expect(tl.length).toEqual(0);
|
expect(tl.length).toEqual(0);
|
||||||
}).nodeify(done);
|
});
|
||||||
|
|
||||||
|
return Promise.all([p1, p3]);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("resending", function() {
|
describe("resending", function() {
|
||||||
|
|||||||
@@ -83,6 +83,8 @@ MatrixScheduler.prototype.removeEventFromQueue = function(event) {
|
|||||||
let removed = false;
|
let removed = false;
|
||||||
utils.removeElement(this._queues[name], function(element) {
|
utils.removeElement(this._queues[name], function(element) {
|
||||||
if (element.event.getId() === event.getId()) {
|
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;
|
removed = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user