Skip to content

Commit

Permalink
Merge pull request #1891 from bugsnag/electron-test-updates
Browse files Browse the repository at this point in the history
Add electron oversized payload tests
  • Loading branch information
djskinner authored Feb 15, 2023
2 parents 218ec45 + 1d57efd commit 493328e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
17 changes: 17 additions & 0 deletions test/electron/features/delivery.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Feature: Delivery of errors

Scenario: Delivery for an oversized error is not retried
Given I launch an app
And I set the next http status code to 400
And I click "main-oversized"
Then the total requests received by the server matches:
| events | 1 |
And the headers of every event request contains:
| Bugsnag-API-Key | 6425093c6530f554a9897d2d7d38e248 |
| Content-Type | application/json |
| Bugsnag-Integrity | {BODY_SHA1} |
# Check that resend is not attempted next load
When I close the app
And I launch an app
Then the total requests received by the server matches:
| events | 1 |
13 changes: 10 additions & 3 deletions test/electron/features/support/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { promisify } = require('util')

class MockServer {
constructor () {
this.responseStatusCode = 202
this.eventUploads = []
this.sessionUploads = []
this.minidumpUploads = []
Expand Down Expand Up @@ -38,19 +39,25 @@ class MockServer {
this.awaitingUploads = []
}

_statusCode () {
var statusCode = this.responseStatusCode
this.responseStatusCode = 202
return statusCode
}

async uploadMinidump (req, res) {
const form = formidable()
form.parse(req, (_err, fields, files) => {
const boundary = this.readBoundary(req.headers['content-type'])
this.minidumpUploads.push({ headers: req.headers, boundary, fields, files })
res.writeHead(202)
res.writeHead(this._statusCode())
res.end()
this._notifyUploads()
})
}

async sendEvent (req, res) {
res.writeHead(202)
res.writeHead(this._statusCode())
let body = ''
req.on('data', (chunk) => { body += chunk })
req.on('end', () => {
Expand All @@ -61,7 +68,7 @@ class MockServer {
}

async sendSession (req, res) {
res.writeHead(202)
res.writeHead(this._statusCode())
let body = ''
req.on('data', (chunk) => { body += chunk })
req.on('end', () => {
Expand Down
4 changes: 4 additions & 0 deletions test/electron/features/support/steps/request-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const featureFlagsTableToExpected = table => {
})
}

Given('I set the next http status code to {int}', (responseCode) => {
global.server.responseStatusCode = responseCode
})

Given('I launch an app', launchConfig, async () => {
return global.automator.start()
})
Expand Down
1 change: 1 addition & 0 deletions test/electron/fixtures/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ <h2>actions</h2>
<li><a href="#" id="main-process-uncaught-exception" onclick="RunnerAPI.mainProcessUncaughtException()">Uncaught exception in main process</a></li>
<li><a href="#" id="main-process-unhandled-promise-rejection" onclick="RunnerAPI.mainProcessUnhandledPromiseRejection()">Unhandled promise rejection in main process</a></li>
<li><a href="#" id="main-notify" onclick="RunnerAPI.mainProcessNotify()">Handled error in main process</a></li>
<li><a href="#" id="main-oversized" onclick="RunnerAPI.mainProcessOversized()">Handled error with oversized payload in main process</a></li>
<li><a href="#" id="child-process-crash" onclick="RunnerAPI.childProcessCrash()">Crash in child process</a></li>
</ul>
<ul>
Expand Down
19 changes: 19 additions & 0 deletions test/electron/fixtures/app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ ipcMain.on('main-process-uncaught-exception', uncaughtException)

ipcMain.on('main-process-notify', notify)

ipcMain.on('main-process-oversized', () => {
function repeat (s, n) {
var a = []
while (a.length < n) {
a.push(s)
}
return a.join('')
}

var big = {}
var i = 0
while (JSON.stringify(big).length < 2 * 10e5) {
big['entry' + i] = repeat('long repetitive string', 1000)
i++
}
Bugsnag.leaveBreadcrumb('big thing', big)
notify()
})

ipcMain.on('main-process-crash', crash)

ipcMain.on('delayed-main-process-crash', () => setTimeout(() => crash(), 1000))
Expand Down
3 changes: 3 additions & 0 deletions test/electron/fixtures/app/preloads/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ contextBridge.exposeInMainWorld('RunnerAPI', {
mainProcessNotify: () => {
ipcRenderer.send('main-process-notify')
},
mainProcessOversized: () => {
ipcRenderer.send('main-process-oversized')
},
mainProcessLog: (...args) => {
ipcRenderer.send('main-process-console-log', ...args)
},
Expand Down

0 comments on commit 493328e

Please sign in to comment.