Skip to content

Commit c785dc3

Browse files
committed
test completely blocked thread
1 parent eafa21b commit c785dc3

File tree

4 files changed

+71
-1
lines changed

4 files changed

+71
-1
lines changed

test/e2e.test.mjs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,42 @@ describe('e2e Tests', { timeout }, () => {
151151
}));
152152
});
153153

154+
test('detect completely blocked thread', async () => {
155+
const result = await runTest(__dirname, 'stalled-forever.js');
156+
157+
expect(result.status).toEqual(0);
158+
159+
expect(result.trace).toEqual(expect.objectContaining({
160+
'0': {
161+
frames: expect.any(Array),
162+
pollState: { some_property: 'main_thread' }
163+
},
164+
'2': {
165+
frames: expect.arrayContaining([
166+
{
167+
function: 'pbkdf2Sync',
168+
filename: expect.any(String),
169+
lineno: expect.any(Number),
170+
colno: expect.any(Number),
171+
},
172+
{
173+
function: 'longWork',
174+
filename: expect.stringMatching(/long-work.js$/),
175+
lineno: expect.any(Number),
176+
colno: expect.any(Number),
177+
},
178+
{
179+
function: '?',
180+
filename: expect.stringMatching(/worker-forever.js$/),
181+
lineno: expect.any(Number),
182+
colno: expect.any(Number),
183+
},
184+
]),
185+
pollState: { some_property: 'worker_thread' },
186+
},
187+
}));
188+
});
189+
154190
test('async storage state', async (ctx) => {
155191
if (NODE_MAJOR_VERSION < 22) {
156192
ctx.skip();

test/long-work.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,11 @@ function longWork() {
88
}
99
}
1010

11-
module.exports = { longWork };
11+
function foreverWork() {
12+
// eslint-disable-next-line no-constant-condition
13+
while (true) {
14+
longWork();
15+
}
16+
}
17+
18+
module.exports = { longWork, foreverWork };

test/stalled-forever.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const { Worker } = require('node:worker_threads');
2+
const { registerThread, threadPoll } = require('@sentry-internal/node-native-stacktrace');
3+
4+
registerThread();
5+
6+
setInterval(() => {
7+
threadPoll(true, { some_property: 'main_thread' });
8+
}, 200).unref();
9+
10+
const watchdog = new Worker('./test/stalled-watchdog.js');
11+
watchdog.on('exit', () => process.exit(0));
12+
13+
const worker = new Worker('./test/worker-forever.js');
14+

test/worker-forever.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const { foreverWork } = require('./long-work');
2+
const { registerThread, threadPoll } = require('@sentry-internal/node-native-stacktrace');
3+
4+
registerThread();
5+
6+
setInterval(() => {
7+
threadPoll(true, { some_property: 'worker_thread' });
8+
}, 200).unref();
9+
10+
setTimeout(() => {
11+
console.log('Starting forever work');
12+
foreverWork();
13+
}, 1000);

0 commit comments

Comments
 (0)