forked from matrix/element-web
Hopefully, fix intermittent test failure
This seeks to fix the intermittent failure of the "MatrixClient rehydrated from stored credentials" tests. The problem appears to be that the 'load_completed' is sometimes taking a while to come through from the dispatcher - or rather, it is taking a long time to get *sent* to the dispatcher: the chain of `q().then().catch().done()` in componentDidMount can take a while to happen. As a workaround, give the test a few goes when waiting for us to start syncing. It's not ideal to be poking into the internal state of MatrixChat like this, but it'll do for now.
This commit is contained in:
parent
6db5329d9c
commit
597705716b
|
@ -94,13 +94,13 @@ describe('loading:', function () {
|
||||||
loadCompletePromise = loadCompleteDefer.promise;
|
loadCompletePromise = loadCompleteDefer.promise;
|
||||||
|
|
||||||
function onNewScreen(screen) {
|
function onNewScreen(screen) {
|
||||||
console.log("newscreen "+screen);
|
console.log(Date.now() + " newscreen "+screen);
|
||||||
if (!appLoaded) {
|
if (!appLoaded) {
|
||||||
lastLoadedScreen = screen;
|
lastLoadedScreen = screen;
|
||||||
} else {
|
} else {
|
||||||
var hash = '#/' + screen;
|
var hash = '#/' + screen;
|
||||||
windowLocation.hash = hash;
|
windowLocation.hash = hash;
|
||||||
console.log("browser URI now "+ windowLocation);
|
console.log(Date.now() + " browser URI now "+ windowLocation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,22 +122,22 @@ describe('loading:', function () {
|
||||||
);
|
);
|
||||||
|
|
||||||
function routeUrl(location, matrixChat) {
|
function routeUrl(location, matrixChat) {
|
||||||
console.log("Routing URL "+location);
|
console.log(Date.now() + " Routing URL "+location);
|
||||||
var fragparts = parseQsFromFragment(location);
|
var fragparts = parseQsFromFragment(location);
|
||||||
matrixChat.showScreen(fragparts.location.substring(1),
|
matrixChat.showScreen(fragparts.location.substring(1),
|
||||||
fragparts.params);
|
fragparts.params);
|
||||||
}
|
}
|
||||||
|
|
||||||
// pause for a cycle, then simulate the window.onload handler
|
// pause for a cycle, then simulate the window.onload handler
|
||||||
q.delay(0).then(() => {
|
window.setTimeout(() => {
|
||||||
console.log("simulating window.onload");
|
console.log(Date.now() + " simulating window.onload");
|
||||||
routeUrl(windowLocation, matrixChat);
|
routeUrl(windowLocation, matrixChat);
|
||||||
appLoaded = true;
|
appLoaded = true;
|
||||||
if (lastLoadedScreen) {
|
if (lastLoadedScreen) {
|
||||||
onNewScreen(lastLoadedScreen);
|
onNewScreen(lastLoadedScreen);
|
||||||
lastLoadedScreen = null;
|
lastLoadedScreen = null;
|
||||||
}
|
}
|
||||||
}).done();
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("Clean load with no stored credentials:", function() {
|
describe("Clean load with no stored credentials:", function() {
|
||||||
|
@ -243,10 +243,8 @@ describe('loading:', function () {
|
||||||
|
|
||||||
loadApp();
|
loadApp();
|
||||||
|
|
||||||
q.delay(1).then(() => {
|
return awaitSyncingSpinner(matrixChat).then(() => {
|
||||||
// we expect a spinner
|
// we got a sync spinner - let the sync complete
|
||||||
assertAtSyncingSpinner(matrixChat);
|
|
||||||
|
|
||||||
return httpBackend.flush();
|
return httpBackend.flush();
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
// once the sync completes, we should have a directory
|
// once the sync completes, we should have a directory
|
||||||
|
@ -266,10 +264,8 @@ describe('loading:', function () {
|
||||||
uriFragment: "#/room/!room:id",
|
uriFragment: "#/room/!room:id",
|
||||||
});
|
});
|
||||||
|
|
||||||
q.delay(1).then(() => {
|
return awaitSyncingSpinner(matrixChat).then(() => {
|
||||||
// we expect a spinner
|
// we got a sync spinner - let the sync complete
|
||||||
assertAtSyncingSpinner(matrixChat);
|
|
||||||
|
|
||||||
return httpBackend.flush();
|
return httpBackend.flush();
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
// once the sync completes, we should have a room view
|
// once the sync completes, we should have a room view
|
||||||
|
@ -300,12 +296,9 @@ describe('loading:', function () {
|
||||||
|
|
||||||
return httpBackend.flush();
|
return httpBackend.flush();
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
// Wait for another trip around the event loop for the UI to update
|
return awaitSyncingSpinner(matrixChat);
|
||||||
return q.delay(1);
|
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
// now we should have a spinner with a logout link
|
// we got a sync spinner - let the sync complete
|
||||||
assertAtSyncingSpinner(matrixChat);
|
|
||||||
|
|
||||||
httpBackend.when('GET', '/sync').respond(200, {});
|
httpBackend.when('GET', '/sync').respond(200, {});
|
||||||
return httpBackend.flush();
|
return httpBackend.flush();
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
|
@ -338,12 +331,8 @@ describe('loading:', function () {
|
||||||
|
|
||||||
return httpBackend.flush();
|
return httpBackend.flush();
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
// Wait for another trip around the event loop for the UI to update
|
return awaitSyncingSpinner(matrixChat);
|
||||||
return q.delay(1);
|
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
// now we should have a spinner with a logout link
|
|
||||||
assertAtSyncingSpinner(matrixChat);
|
|
||||||
|
|
||||||
httpBackend.when('GET', '/sync').check(function(req) {
|
httpBackend.when('GET', '/sync').check(function(req) {
|
||||||
expect(req.path).toMatch(new RegExp("^https://homeserver/"));
|
expect(req.path).toMatch(new RegExp("^https://homeserver/"));
|
||||||
}).respond(200, {});
|
}).respond(200, {});
|
||||||
|
@ -377,12 +366,8 @@ describe('loading:', function () {
|
||||||
|
|
||||||
return httpBackend.flush();
|
return httpBackend.flush();
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
// Wait for another trip around the event loop for the UI to update
|
return awaitSyncingSpinner(matrixChat);
|
||||||
return q.delay(1);
|
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
// now we should have a spinner with a logout link
|
|
||||||
assertAtSyncingSpinner(matrixChat);
|
|
||||||
|
|
||||||
httpBackend.when('GET', '/sync').respond(200, {});
|
httpBackend.when('GET', '/sync').respond(200, {});
|
||||||
return httpBackend.flush();
|
return httpBackend.flush();
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
|
@ -448,6 +433,32 @@ function assertAtLoadingSpinner(matrixChat) {
|
||||||
|
|
||||||
// we've got login creds, and are waiting for the sync to finish.
|
// we've got login creds, and are waiting for the sync to finish.
|
||||||
// the page includes a logout link.
|
// the page includes a logout link.
|
||||||
|
function awaitSyncingSpinner(matrixChat, retryLimit, retryCount) {
|
||||||
|
if (retryLimit === undefined) {
|
||||||
|
retryLimit = 5;
|
||||||
|
}
|
||||||
|
if (retryCount === undefined) {
|
||||||
|
retryCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (matrixChat.state.loading) {
|
||||||
|
console.log(Date.now() + " Awaiting sync spinner: still loading.");
|
||||||
|
if (retryCount >= retryLimit) {
|
||||||
|
throw new Error("MatrixChat still not loaded after " +
|
||||||
|
retryCount + " tries");
|
||||||
|
}
|
||||||
|
return q.delay(0).then(() => {
|
||||||
|
return awaitSyncingSpinner(matrixChat, retryLimit, retryCount + 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(Date.now() + " Awaiting sync spinner: load complete.");
|
||||||
|
|
||||||
|
// state looks good, check the rendered output
|
||||||
|
assertAtSyncingSpinner(matrixChat);
|
||||||
|
return q();
|
||||||
|
}
|
||||||
|
|
||||||
function assertAtSyncingSpinner(matrixChat) {
|
function assertAtSyncingSpinner(matrixChat) {
|
||||||
var domComponent = ReactDOM.findDOMNode(matrixChat);
|
var domComponent = ReactDOM.findDOMNode(matrixChat);
|
||||||
expect(domComponent.className).toEqual("mx_MatrixChat_splash");
|
expect(domComponent.className).toEqual("mx_MatrixChat_splash");
|
||||||
|
|
Loading…
Reference in New Issue