From f19ccec383c4bbf44fa2cf5f9c67362b9212b247 Mon Sep 17 00:00:00 2001 From: johnjbarton Date: Mon, 21 Dec 2020 16:52:37 -0800 Subject: [PATCH] chore(test): mark all second connections reconnects The reconnecting test is flakey, sometimes running the tests twice. This is exactly the behavior we are trying to prevent. Hard to reproduce. --- client/karma.js | 11 +++++------ static/karma.js | 12 ++++++------ test/e2e/reconnecting.feature | 1 + test/e2e/support/reconnecting/test.js | 15 +++++++-------- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/client/karma.js b/client/karma.js index 6790a77ac..a0ba6cddf 100644 --- a/client/karma.js +++ b/client/karma.js @@ -41,9 +41,11 @@ function Karma (socket, iframe, opener, navigator, location, document) { } } - // This variable will be set to "true" whenever the socket lost connection and was able to - // reconnect to the Karma server. This will be passed to the Karma server then, so that - // Karma can differentiate between a socket client reconnect and a full browser reconnect. + // To start we will signal the server that we are not reconnecting. If the socket loses + // connection and was able to reconnect to the Karma server we will get a + // second 'connect' event. There we will pass 'true' and that will be passed to the + // Karma server then, so that Karma can differentiate between a socket client + // econnect and a full browser reconnect. var socketReconnect = false this.VERSION = constant.VERSION @@ -306,9 +308,6 @@ function Karma (socket, iframe, opener, navigator, location, document) { info.displayName = displayName } socket.emit('register', info) - }) - - socket.on('reconnect', function () { socketReconnect = true }) } diff --git a/static/karma.js b/static/karma.js index 0c289e0ca..370f41fde 100644 --- a/static/karma.js +++ b/static/karma.js @@ -51,9 +51,11 @@ function Karma (socket, iframe, opener, navigator, location, document) { } } - // This variable will be set to "true" whenever the socket lost connection and was able to - // reconnect to the Karma server. This will be passed to the Karma server then, so that - // Karma can differentiate between a socket client reconnect and a full browser reconnect. + // To start we will signal the server that we are not reconnecting. If the socket loses + // connection and was able to reconnect to the Karma server we will get a + // second 'connect' event. There we will pass 'true' and that will be passed to the + // Karma server then, so that Karma can differentiate between a socket client + // econnect and a full browser reconnect. var socketReconnect = false this.VERSION = constant.VERSION @@ -316,11 +318,9 @@ function Karma (socket, iframe, opener, navigator, location, document) { info.displayName = displayName } socket.emit('register', info) - }) - - socket.on('reconnect', function () { socketReconnect = true }) + } module.exports = Karma diff --git a/test/e2e/reconnecting.feature b/test/e2e/reconnecting.feature index 829cbaec7..246d4e0da 100644 --- a/test/e2e/reconnecting.feature +++ b/test/e2e/reconnecting.feature @@ -21,6 +21,7 @@ Feature: Passing Options When I start Karma Then it passes with: """ + LOG: '============== START TEST ==============' ..... Chrome Headless """ diff --git a/test/e2e/support/reconnecting/test.js b/test/e2e/support/reconnecting/test.js index a3b682e1b..74216c7fe 100644 --- a/test/e2e/support/reconnecting/test.js +++ b/test/e2e/support/reconnecting/test.js @@ -6,27 +6,26 @@ describe('plus', function () { } it('should pass', function () { + // In flaky fails we probably get two starts. + console.log('============== START TEST ==============') expect(1).toBe(1) }) it('should disconnect', function (done) { expect(2).toBe(2) - socket().disconnect() - - done() + setTimeout(() => { + socket().disconnect() + done() + }, 500) }) it('should work', function () { expect(plus(1, 2)).toBe(3) }) - it('should re-connect', function (done) { + it('should re-connect', function () { expect(4).toBe(4) - // Emit reconnect, so Karma will not start new test run after reconnecting. - socket().emit('reconnect') socket().connect() - - done() }) it('should work', function () {