-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes cypress crash (ECONNRESET) on socket hang up during attempted s…
…ocket upgrade (#1382) * Fixes cypress crash on socket hang up during attempted upgrade * Fixing broken tests * Do something with the error * Added unit test * Handle error with 500 status * Reverting to just end the response * handle web socket errors gracefully, send 502 bad gateway - adds e2e + integration tests * fixes failing tests * fixes failing e2e tests
- Loading branch information
1 parent
fc374e1
commit 746f62e
Showing
9 changed files
with
172 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
exports['e2e websockets passes 1'] = ` | ||
Started video recording: /foo/bar/.projects/e2e/cypress/videos/abc123.mp4 | ||
|
||
(Tests Starting) | ||
|
||
|
||
websockets | ||
✓ does not crash | ||
|
||
|
||
1 passing | ||
|
||
|
||
(Tests Finished) | ||
|
||
- Tests: 1 | ||
- Passes: 1 | ||
- Failures: 0 | ||
- Pending: 0 | ||
- Duration: 10 seconds | ||
- Screenshots: 0 | ||
- Video Recorded: true | ||
- Cypress Version: 1.2.3 | ||
|
||
|
||
(Video) | ||
|
||
- Started processing: Compressing to 32 CRF | ||
- Finished processing: /foo/bar/.projects/e2e/cypress/videos/abc123.mp4 (0 seconds) | ||
|
||
|
||
(All Done) | ||
|
||
` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
ws = require("ws") | ||
|
||
e2e = require("../support/helpers/e2e") | ||
|
||
onServer = (app) -> | ||
app.get "/foo", (req, res) -> | ||
res.send("<html>foo></html>") | ||
|
||
onWsServer = (app, server) -> | ||
wss = new ws.Server({ server }) | ||
wss.on "connection", (ws) -> | ||
ws.on "message", (msg) -> | ||
ws.send(msg + "bar") | ||
|
||
onWssServer = (app) -> | ||
|
||
describe "e2e websockets", -> | ||
e2e.setup({ | ||
servers: [{ | ||
port: 3038 | ||
static: true | ||
onServer: onServer | ||
}, { | ||
port: 3039 | ||
onServer: onWsServer | ||
}, { | ||
port: 3040 | ||
onServer: onWssServer | ||
}] | ||
}) | ||
|
||
## https://github.com/cypress-io/cypress/issues/556 | ||
it "passes", -> | ||
e2e.exec(@, { | ||
spec: "websockets_spec.coffee" | ||
snapshot: true | ||
expectedExitCode: 0 | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...ages/server/test/support/fixtures/projects/e2e/cypress/integration/websockets_spec.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
urlClosesWithCode1006 = (win, url) -> | ||
new Promise (resolve, reject) -> | ||
ws = new win.WebSocket(url) | ||
|
||
# ws.onerror = (err) -> | ||
# debugger | ||
|
||
ws.onclose = (evt) -> | ||
if evt.code is 1006 | ||
resolve() | ||
else | ||
reject("websocket connection should have been closed with code 1006 for url: #{url} but was instead closed with code: #{evt.code}") | ||
|
||
ws.onopen = (evt) -> | ||
reject("websocket connection should not have opened for url: #{url}") | ||
|
||
describe "websockets", -> | ||
it "does not crash", -> | ||
cy.visit("http://localhost:3038/foo") | ||
cy.log("should not crash on ECONNRESET websocket upgrade") | ||
cy.window().then (win) -> | ||
Cypress.Promise.all([ | ||
urlClosesWithCode1006(win, "ws://localhost:3038/websocket") | ||
urlClosesWithCode1006(win, "wss://localhost:3040/websocket") | ||
]) | ||
|
||
cy.log("should be able to send websocket messages") | ||
|
||
cy | ||
.window() | ||
.then (win) -> | ||
new Promise (resolve, reject) -> | ||
ws = new win.WebSocket("ws://localhost:3039/") | ||
ws.onmessage = (evt) -> | ||
resolve(evt.data) | ||
ws.onerror = reject | ||
ws.onopen = -> | ||
ws.send("foo") | ||
.should("eq", "foobar") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters