From a20ed2f6324e5818399bb06e93ba76bb83cc50eb Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 5 Jul 2017 16:20:21 +0100 Subject: [PATCH] Add some logging to track down flaky test We had a test failure where apparently the MatrixClient failed to start ... let's try and figure out why. --- src/Lifecycle.js | 2 ++ src/MatrixClientPeg.js | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Lifecycle.js b/src/Lifecycle.js index 06f5d9ef00..f64e2b3858 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -419,6 +419,8 @@ export function logout() { * listen for events while a session is logged in. */ function startMatrixClient() { + console.log(`Lifecycle: Starting MatrixClient`); + // dispatch this before starting the matrix client: it's used // to add listeners for the 'sync' event so otherwise we'd have // a race condition (and we need to dispatch synchronously for this diff --git a/src/MatrixClientPeg.js b/src/MatrixClientPeg.js index 0676e4600f..b31cf7511e 100644 --- a/src/MatrixClientPeg.js +++ b/src/MatrixClientPeg.js @@ -77,22 +77,26 @@ class MatrixClientPeg { this._createClient(creds); } - start() { + async start() { const opts = utils.deepCopy(this.opts); // the react sdk doesn't work without this, so don't allow opts.pendingEventOrdering = "detached"; - let promise = this.matrixClient.store.startup(); - // log any errors when starting up the database (if one exists) - promise.catch((err) => { + try { + let promise = this.matrixClient.store.startup(); + console.log(`MatrixClientPeg: waiting for MatrixClient store to initialise`); + await promise; + } catch(err) { + // log any errors when starting up the database (if one exists) console.error(`Error starting matrixclient store: ${err}`); - }); + } // regardless of errors, start the client. If we did error out, we'll // just end up doing a full initial /sync. - promise.finally(() => { - this.get().startClient(opts); - }); + + console.log(`MatrixClientPeg: really starting MatrixClient`); + this.get().startClient(opts); + console.log(`MatrixClientPeg: MatrixClient started`); } getCredentials(): MatrixClientCreds {