Skip to content

Commit

Permalink
chore(test): mark all second connections reconnects
Browse files Browse the repository at this point in the history
The reconnecting test is flakey, sometimes running the tests twice. This is exactly
the behavior we are trying to prevent. Hard to reproduce.
  • Loading branch information
johnjbarton committed Dec 22, 2020
1 parent 1a65bf1 commit f19ccec
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
11 changes: 5 additions & 6 deletions client/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
})
}
Expand Down
12 changes: 6 additions & 6 deletions static/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/e2e/reconnecting.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Feature: Passing Options
When I start Karma
Then it passes with:
"""
LOG: '============== START TEST =============='
.....
Chrome Headless
"""
15 changes: 7 additions & 8 deletions test/e2e/support/reconnecting/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit f19ccec

Please sign in to comment.