Restart crash service in each spec
This commit is contained in:
parent
a7a92e1cd3
commit
de62f1ea6c
5 changed files with 55 additions and 5 deletions
|
@ -56,7 +56,7 @@ class CrashReporter {
|
||||||
const env = {
|
const env = {
|
||||||
ELECTRON_INTERNAL_CRASH_SERVICE: 1
|
ELECTRON_INTERNAL_CRASH_SERVICE: 1
|
||||||
}
|
}
|
||||||
spawn(process.execPath, args, {
|
this._crashServiceProcess = spawn(process.execPath, args, {
|
||||||
env: env,
|
env: env,
|
||||||
detached: true
|
detached: true
|
||||||
})
|
})
|
||||||
|
|
|
@ -46,6 +46,10 @@ describe('crashReporter module', function () {
|
||||||
return closeWindow(w).then(function () { w = null })
|
return closeWindow(w).then(function () { w = null })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
afterEach(function () {
|
||||||
|
stopCrashService()
|
||||||
|
})
|
||||||
|
|
||||||
afterEach(function (done) {
|
afterEach(function (done) {
|
||||||
if (stopServer != null) {
|
if (stopServer != null) {
|
||||||
stopServer(done)
|
stopServer(done)
|
||||||
|
@ -82,9 +86,24 @@ describe('crashReporter module', function () {
|
||||||
|
|
||||||
stopServer = startServer({
|
stopServer = startServer({
|
||||||
callback (port) {
|
callback (port) {
|
||||||
const crashesDir = path.join(app.getPath('temp'), `${app.getName()} Crashes`)
|
const crashesDir = path.join(app.getPath('temp'), `Zombies Crashes`)
|
||||||
const version = app.getVersion()
|
const version = app.getVersion()
|
||||||
const crashPath = path.join(fixtures, 'module', 'crash.js')
|
const crashPath = path.join(fixtures, 'module', 'crash.js')
|
||||||
|
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
const crashServiceProcess = childProcess.spawn(process.execPath, [
|
||||||
|
`--reporter-url=http://127.0.0.1:${port}`,
|
||||||
|
'--application-name=Zombies',
|
||||||
|
`--crashes-directory=${crashesDir}`
|
||||||
|
], {
|
||||||
|
env: {
|
||||||
|
ELECTRON_INTERNAL_CRASH_SERVICE: 1
|
||||||
|
},
|
||||||
|
detached: true
|
||||||
|
})
|
||||||
|
remote.process.crashServicePid = crashServiceProcess.pid
|
||||||
|
}
|
||||||
|
|
||||||
childProcess.fork(crashPath, [port, version, crashesDir], {silent: true})
|
childProcess.fork(crashPath, [port, version, crashesDir], {silent: true})
|
||||||
},
|
},
|
||||||
processType: 'browser',
|
processType: 'browser',
|
||||||
|
@ -105,7 +124,7 @@ describe('crashReporter module', function () {
|
||||||
}
|
}
|
||||||
const testDone = (uploaded) => {
|
const testDone = (uploaded) => {
|
||||||
if (uploaded) {
|
if (uploaded) {
|
||||||
return done(new Error('fail'))
|
return done(new Error('Uploaded crash report'))
|
||||||
}
|
}
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
crashReporter.setUploadToServer(true)
|
crashReporter.setUploadToServer(true)
|
||||||
|
@ -321,3 +340,17 @@ const startServer = ({callback, processType, done}) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const stopCrashService = () => {
|
||||||
|
const {crashServicePid} = remote.process
|
||||||
|
if (crashServicePid) {
|
||||||
|
remote.process.crashServicePid = 0
|
||||||
|
try {
|
||||||
|
process.kill(crashServicePid)
|
||||||
|
} catch (error) {
|
||||||
|
if (error.code !== 'ESRCH') {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
6
spec/fixtures/api/crash-restart.html
vendored
6
spec/fixtures/api/crash-restart.html
vendored
|
@ -3,7 +3,7 @@
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
|
||||||
const {port} = require('url').parse(window.location.href, true).query
|
const {port} = require('url').parse(window.location.href, true).query
|
||||||
const {crashReporter} = require('electron')
|
const {crashReporter, ipcRenderer} = require('electron')
|
||||||
|
|
||||||
crashReporter.start({
|
crashReporter.start({
|
||||||
productName: 'Zombies',
|
productName: 'Zombies',
|
||||||
|
@ -18,6 +18,10 @@ crashReporter.start({
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
ipcRenderer.sendSync('crash-service-pid', crashReporter._crashServiceProcess.pid)
|
||||||
|
}
|
||||||
|
|
||||||
setImmediate(() => {
|
setImmediate(() => {
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
crashReporter.setExtraParameter('extra2', 'extra2')
|
crashReporter.setExtraParameter('extra2', 'extra2')
|
||||||
|
|
5
spec/fixtures/api/crash.html
vendored
5
spec/fixtures/api/crash.html
vendored
|
@ -16,6 +16,11 @@ crashReporter.start({
|
||||||
'extra2': 'extra2',
|
'extra2': 'extra2',
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
ipcRenderer.sendSync('crash-service-pid', crashReporter._crashServiceProcess.pid)
|
||||||
|
}
|
||||||
|
|
||||||
if (!uploadToServer) {
|
if (!uploadToServer) {
|
||||||
ipcRenderer.sendSync('list-existing-dumps')
|
ipcRenderer.sendSync('list-existing-dumps')
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,10 @@ var argv = require('yargs')
|
||||||
.argv
|
.argv
|
||||||
|
|
||||||
var window = null
|
var window = null
|
||||||
process.port = 0 // will be used by crash-reporter spec.
|
|
||||||
|
// will be used by crash-reporter spec.
|
||||||
|
process.port = 0
|
||||||
|
process.crashServicePid = 0
|
||||||
|
|
||||||
v8.setFlagsFromString('--expose_gc')
|
v8.setFlagsFromString('--expose_gc')
|
||||||
app.commandLine.appendSwitch('js-flags', '--expose_gc')
|
app.commandLine.appendSwitch('js-flags', '--expose_gc')
|
||||||
|
@ -329,6 +332,11 @@ ipcMain.on('navigate-with-pending-entry', (event, id) => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ipcMain.on('crash-service-pid', (event, pid) => {
|
||||||
|
process.crashServicePid = pid
|
||||||
|
event.returnValue = null
|
||||||
|
})
|
||||||
|
|
||||||
// Suspend listeners until the next event and then restore them
|
// Suspend listeners until the next event and then restore them
|
||||||
const suspendListeners = (emitter, eventName, callback) => {
|
const suspendListeners = (emitter, eventName, callback) => {
|
||||||
const listeners = emitter.listeners(eventName)
|
const listeners = emitter.listeners(eventName)
|
||||||
|
|
Loading…
Reference in a new issue