From b849c203897304124810d41f5062879a635fd83e Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Tue, 21 Jan 2025 10:45:44 +0100 Subject: [PATCH] test: More child process types (#1063) --- .../native-sentry/child-exec/event.json | 75 +++++++++++++++++ .../native-sentry/child-exec/package.json | 9 ++ .../native-sentry/child-exec/recipe.yml | 5 ++ .../native-sentry/child-exec/src/index.html | 15 ++++ .../native-sentry/child-exec/src/main.js | 37 +++++++++ .../native-sentry/child-fork/event.json | 75 +++++++++++++++++ .../native-sentry/child-fork/package.json | 9 ++ .../native-sentry/child-fork/recipe.yml | 5 ++ .../native-sentry/child-fork/src/child.js | 5 ++ .../native-sentry/child-fork/src/index.html | 15 ++++ .../native-sentry/child-fork/src/main.js | 32 +++++++ .../native-sentry/utility/event.json | 83 +++++++++++++++++++ .../native-sentry/utility/package.json | 9 ++ .../native-sentry/utility/recipe.yml | 5 ++ .../native-sentry/utility/src/child.js | 5 ++ .../native-sentry/utility/src/index.html | 15 ++++ .../native-sentry/utility/src/main.js | 25 ++++++ 17 files changed, 424 insertions(+) create mode 100644 test/e2e/test-apps/native-sentry/child-exec/event.json create mode 100644 test/e2e/test-apps/native-sentry/child-exec/package.json create mode 100644 test/e2e/test-apps/native-sentry/child-exec/recipe.yml create mode 100644 test/e2e/test-apps/native-sentry/child-exec/src/index.html create mode 100644 test/e2e/test-apps/native-sentry/child-exec/src/main.js create mode 100644 test/e2e/test-apps/native-sentry/child-fork/event.json create mode 100644 test/e2e/test-apps/native-sentry/child-fork/package.json create mode 100644 test/e2e/test-apps/native-sentry/child-fork/recipe.yml create mode 100644 test/e2e/test-apps/native-sentry/child-fork/src/child.js create mode 100644 test/e2e/test-apps/native-sentry/child-fork/src/index.html create mode 100644 test/e2e/test-apps/native-sentry/child-fork/src/main.js create mode 100644 test/e2e/test-apps/native-sentry/utility/event.json create mode 100644 test/e2e/test-apps/native-sentry/utility/package.json create mode 100644 test/e2e/test-apps/native-sentry/utility/recipe.yml create mode 100644 test/e2e/test-apps/native-sentry/utility/src/child.js create mode 100644 test/e2e/test-apps/native-sentry/utility/src/index.html create mode 100644 test/e2e/test-apps/native-sentry/utility/src/main.js diff --git a/test/e2e/test-apps/native-sentry/child-exec/event.json b/test/e2e/test-apps/native-sentry/child-exec/event.json new file mode 100644 index 00000000..6c7bc91b --- /dev/null +++ b/test/e2e/test-apps/native-sentry/child-exec/event.json @@ -0,0 +1,75 @@ +{ + "method": "envelope", + "sentryKey": "37f8a2ee37c0409d8970bc7559c7c7e4", + "appId": "277345", + "data": { + "sdk": { + "name": "sentry.javascript.electron", + "packages": [ + { + "name": "npm:@sentry/electron", + "version": "{{version}}" + } + ], + "version": "{{version}}" + }, + "contexts": { + "app": { + "app_name": "native-sentry-child-exec", + "app_version": "1.0.0", + "app_start_time": "{{time}}" + }, + "browser": { + "name": "Chrome" + }, + "chrome": { + "name": "Chrome", + "type": "runtime", + "version": "{{version}}" + }, + "device": { + "arch": "{{arch}}", + "family": "Desktop", + "memory_size": 0, + "free_memory": 0, + "processor_count": 0, + "processor_frequency": 0, + "cpu_description": "{{cpu}}", + "screen_resolution": "{{screen}}", + "screen_density": 1 + }, + "culture": { + "locale": "{{locale}}", + "timezone": "{{timezone}}" + }, + "node": { + "name": "Node", + "type": "runtime", + "version": "{{version}}" + }, + "os": { + "name": "{{platform}}", + "version": "{{version}}" + }, + "runtime": { + "name": "Electron", + "version": "{{version}}" + } + }, + "release": "native-sentry-child-exec@1.0.0", + "environment": "development", + "event_id": "{{id}}", + "timestamp": 0, + "breadcrumbs": [], + "tags": { + "event.environment": "native", + "event.origin": "electron", + "event.process": "unknown" + } + }, + "attachments": [ + { + "attachment_type": "event.minidump" + } + ] +} diff --git a/test/e2e/test-apps/native-sentry/child-exec/package.json b/test/e2e/test-apps/native-sentry/child-exec/package.json new file mode 100644 index 00000000..059b1d62 --- /dev/null +++ b/test/e2e/test-apps/native-sentry/child-exec/package.json @@ -0,0 +1,9 @@ +{ + "name": "native-sentry-child-exec", + "version": "1.0.0", + "main": "src/main.js", + "dependencies": { + "@sentry/electron": "5.6.0", + "crashy-cli": "1.0.1" + } +} diff --git a/test/e2e/test-apps/native-sentry/child-exec/recipe.yml b/test/e2e/test-apps/native-sentry/child-exec/recipe.yml new file mode 100644 index 00000000..307d733a --- /dev/null +++ b/test/e2e/test-apps/native-sentry/child-exec/recipe.yml @@ -0,0 +1,5 @@ +description: Native Child Exec Crash +category: Native (Sentry Uploader) +command: yarn +runTwice: true +condition: platform === 'darwin' diff --git a/test/e2e/test-apps/native-sentry/child-exec/src/index.html b/test/e2e/test-apps/native-sentry/child-exec/src/index.html new file mode 100644 index 00000000..26aca209 --- /dev/null +++ b/test/e2e/test-apps/native-sentry/child-exec/src/index.html @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/test/e2e/test-apps/native-sentry/child-exec/src/main.js b/test/e2e/test-apps/native-sentry/child-exec/src/main.js new file mode 100644 index 00000000..393f9093 --- /dev/null +++ b/test/e2e/test-apps/native-sentry/child-exec/src/main.js @@ -0,0 +1,37 @@ +const path = require('path'); +const child_process = require('child_process'); + +const { getPath } = require('crashy-cli'); +const { app, BrowserWindow } = require('electron'); +const { init } = require('@sentry/electron/main'); + +init({ + dsn: '__DSN__', + debug: true, + autoSessionTracking: false, + onFatalError: () => {}, +}); + +app.on('ready', () => { + const mainWindow = new BrowserWindow({ + show: false, + webPreferences: { + nodeIntegration: true, + contextIsolation: false, + }, + }); + + mainWindow.loadFile(path.join(__dirname, 'index.html')); + + if (process.env.APP_FIRST_RUN) { + try { + child_process.execSync(getPath()); + } catch (_) { + // + } + + setTimeout(() => { + app.exit(); + }, 3000); + } +}); diff --git a/test/e2e/test-apps/native-sentry/child-fork/event.json b/test/e2e/test-apps/native-sentry/child-fork/event.json new file mode 100644 index 00000000..34a6c63f --- /dev/null +++ b/test/e2e/test-apps/native-sentry/child-fork/event.json @@ -0,0 +1,75 @@ +{ + "method": "envelope", + "sentryKey": "37f8a2ee37c0409d8970bc7559c7c7e4", + "appId": "277345", + "data": { + "sdk": { + "name": "sentry.javascript.electron", + "packages": [ + { + "name": "npm:@sentry/electron", + "version": "{{version}}" + } + ], + "version": "{{version}}" + }, + "contexts": { + "app": { + "app_name": "native-sentry-child-fork", + "app_version": "1.0.0", + "app_start_time": "{{time}}" + }, + "browser": { + "name": "Chrome" + }, + "chrome": { + "name": "Chrome", + "type": "runtime", + "version": "{{version}}" + }, + "device": { + "arch": "{{arch}}", + "family": "Desktop", + "memory_size": 0, + "free_memory": 0, + "processor_count": 0, + "processor_frequency": 0, + "cpu_description": "{{cpu}}", + "screen_resolution": "{{screen}}", + "screen_density": 1 + }, + "culture": { + "locale": "{{locale}}", + "timezone": "{{timezone}}" + }, + "node": { + "name": "Node", + "type": "runtime", + "version": "{{version}}" + }, + "os": { + "name": "{{platform}}", + "version": "{{version}}" + }, + "runtime": { + "name": "Electron", + "version": "{{version}}" + } + }, + "release": "native-sentry-child-fork@1.0.0", + "environment": "development", + "event_id": "{{id}}", + "timestamp": 0, + "breadcrumbs": [], + "tags": { + "event.environment": "native", + "event.origin": "electron", + "event.process": "node" + } + }, + "attachments": [ + { + "attachment_type": "event.minidump" + } + ] +} diff --git a/test/e2e/test-apps/native-sentry/child-fork/package.json b/test/e2e/test-apps/native-sentry/child-fork/package.json new file mode 100644 index 00000000..8d93dedd --- /dev/null +++ b/test/e2e/test-apps/native-sentry/child-fork/package.json @@ -0,0 +1,9 @@ +{ + "name": "native-sentry-child-fork", + "version": "1.0.0", + "main": "src/main.js", + "dependencies": { + "@sentry/electron": "5.6.0", + "sadness-generator": "0.0.2" + } +} diff --git a/test/e2e/test-apps/native-sentry/child-fork/recipe.yml b/test/e2e/test-apps/native-sentry/child-fork/recipe.yml new file mode 100644 index 00000000..fe944a67 --- /dev/null +++ b/test/e2e/test-apps/native-sentry/child-fork/recipe.yml @@ -0,0 +1,5 @@ +description: Native Child Crash +category: Native (Sentry Uploader) +command: yarn +runTwice: true +condition: platform !== 'linux' diff --git a/test/e2e/test-apps/native-sentry/child-fork/src/child.js b/test/e2e/test-apps/native-sentry/child-fork/src/child.js new file mode 100644 index 00000000..6ea883a0 --- /dev/null +++ b/test/e2e/test-apps/native-sentry/child-fork/src/child.js @@ -0,0 +1,5 @@ +const { raiseSegfault } = require('sadness-generator') + +setTimeout(() => { + raiseSegfault(); +}, 1000); diff --git a/test/e2e/test-apps/native-sentry/child-fork/src/index.html b/test/e2e/test-apps/native-sentry/child-fork/src/index.html new file mode 100644 index 00000000..26aca209 --- /dev/null +++ b/test/e2e/test-apps/native-sentry/child-fork/src/index.html @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/test/e2e/test-apps/native-sentry/child-fork/src/main.js b/test/e2e/test-apps/native-sentry/child-fork/src/main.js new file mode 100644 index 00000000..b9195f57 --- /dev/null +++ b/test/e2e/test-apps/native-sentry/child-fork/src/main.js @@ -0,0 +1,32 @@ +const path = require('path'); +const child_process = require('child_process'); + +const { app, BrowserWindow } = require('electron'); +const { init } = require('@sentry/electron/main'); + +init({ + dsn: '__DSN__', + debug: true, + autoSessionTracking: false, + onFatalError: () => {}, +}); + +app.on('ready', () => { + const mainWindow = new BrowserWindow({ + show: false, + webPreferences: { + nodeIntegration: true, + contextIsolation: false, + }, + }); + + mainWindow.loadFile(path.join(__dirname, 'index.html')); + + if (process.env.APP_FIRST_RUN) { + child_process.fork(path.join(__dirname, 'child.js')); + + setTimeout(() => { + app.exit(); + }, 3000); + } +}); diff --git a/test/e2e/test-apps/native-sentry/utility/event.json b/test/e2e/test-apps/native-sentry/utility/event.json new file mode 100644 index 00000000..1fa76edb --- /dev/null +++ b/test/e2e/test-apps/native-sentry/utility/event.json @@ -0,0 +1,83 @@ +{ + "method": "envelope", + "sentryKey": "37f8a2ee37c0409d8970bc7559c7c7e4", + "appId": "277345", + "data": { + "sdk": { + "name": "sentry.javascript.electron", + "packages": [ + { + "name": "npm:@sentry/electron", + "version": "{{version}}" + } + ], + "version": "{{version}}" + }, + "contexts": { + "app": { + "app_name": "native-sentry-utility", + "app_version": "1.0.0", + "app_start_time": "{{time}}" + }, + "browser": { + "name": "Chrome" + }, + "chrome": { + "name": "Chrome", + "type": "runtime", + "version": "{{version}}" + }, + "device": { + "arch": "{{arch}}", + "family": "Desktop", + "memory_size": 0, + "free_memory": 0, + "processor_count": 0, + "processor_frequency": 0, + "cpu_description": "{{cpu}}", + "screen_resolution": "{{screen}}", + "screen_density": 1 + }, + "culture": { + "locale": "{{locale}}", + "timezone": "{{timezone}}" + }, + "node": { + "name": "Node", + "type": "runtime", + "version": "{{version}}" + }, + "os": { + "name": "{{platform}}", + "version": "{{version}}" + }, + "runtime": { + "name": "Electron", + "version": "{{version}}" + }, + "electron": { + "details": { + "name": "Node Utility Process", + "reason": "crashed", + "type": "Utility" + } + } + }, + "release": "native-sentry-utility@1.0.0", + "environment": "development", + "event_id": "{{id}}", + "timestamp": 0, + "breadcrumbs": [], + "tags": { + "event.environment": "native", + "event.origin": "electron", + "event.process": "utility", + "exit.reason": "crashed" + } + }, + "attachments": [ + { + "attachment_type": "event.minidump" + } + ] +} diff --git a/test/e2e/test-apps/native-sentry/utility/package.json b/test/e2e/test-apps/native-sentry/utility/package.json new file mode 100644 index 00000000..1f6bb125 --- /dev/null +++ b/test/e2e/test-apps/native-sentry/utility/package.json @@ -0,0 +1,9 @@ +{ + "name": "native-sentry-utility", + "version": "1.0.0", + "main": "src/main.js", + "dependencies": { + "@sentry/electron": "5.6.0", + "sadness-generator": "0.0.2" + } +} diff --git a/test/e2e/test-apps/native-sentry/utility/recipe.yml b/test/e2e/test-apps/native-sentry/utility/recipe.yml new file mode 100644 index 00000000..8bef0a16 --- /dev/null +++ b/test/e2e/test-apps/native-sentry/utility/recipe.yml @@ -0,0 +1,5 @@ +description: Native Utility Crash +category: Native (Sentry Uploader) +command: yarn +# Not working on Linux with v29.4.6 +condition: version.major >= 22 && !(platform === 'linux' && version.major === 29) diff --git a/test/e2e/test-apps/native-sentry/utility/src/child.js b/test/e2e/test-apps/native-sentry/utility/src/child.js new file mode 100644 index 00000000..6ea883a0 --- /dev/null +++ b/test/e2e/test-apps/native-sentry/utility/src/child.js @@ -0,0 +1,5 @@ +const { raiseSegfault } = require('sadness-generator') + +setTimeout(() => { + raiseSegfault(); +}, 1000); diff --git a/test/e2e/test-apps/native-sentry/utility/src/index.html b/test/e2e/test-apps/native-sentry/utility/src/index.html new file mode 100644 index 00000000..26aca209 --- /dev/null +++ b/test/e2e/test-apps/native-sentry/utility/src/index.html @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/test/e2e/test-apps/native-sentry/utility/src/main.js b/test/e2e/test-apps/native-sentry/utility/src/main.js new file mode 100644 index 00000000..b22f8563 --- /dev/null +++ b/test/e2e/test-apps/native-sentry/utility/src/main.js @@ -0,0 +1,25 @@ +const path = require('path'); + +const { app, BrowserWindow, utilityProcess } = require('electron'); +const { init } = require('@sentry/electron/main'); + +init({ + dsn: '__DSN__', + debug: true, + autoSessionTracking: false, + onFatalError: () => {}, +}); + +app.on('ready', () => { + const mainWindow = new BrowserWindow({ + show: false, + webPreferences: { + nodeIntegration: true, + contextIsolation: false, + }, + }); + + mainWindow.loadFile(path.join(__dirname, 'index.html')); + + utilityProcess.fork(path.join(__dirname, 'child.js'), {stdio:'inherit'}); +});