Skip to content

Commit 7c7c45a

Browse files
committed
Add tests
1 parent 450b420 commit 7c7c45a

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import * as assert from 'assert';
2+
import * as crypto from 'crypto';
3+
4+
import * as Sentry from '@sentry/node';
5+
6+
global._sentryDebugIds = { [new Error().stack]: 'aaaaaaaa-aaaa-4aaa-aaaa-aaaaaaaaaa' };
7+
8+
setTimeout(() => {
9+
process.exit();
10+
}, 10000);
11+
12+
Sentry.init({
13+
dsn: process.env.SENTRY_DSN,
14+
release: '1.0',
15+
autoSessionTracking: false,
16+
integrations: [Sentry.anrIntegration({ captureStackTrace: true, anrThreshold: 100, maxAnrEvents: 2 })],
17+
});
18+
19+
Sentry.setUser({ email: '[email protected]' });
20+
Sentry.addBreadcrumb({ message: 'important message!' });
21+
22+
function longWork() {
23+
for (let i = 0; i < 20; i++) {
24+
const salt = crypto.randomBytes(128).toString('base64');
25+
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
26+
assert.ok(hash);
27+
}
28+
}
29+
30+
setTimeout(() => {
31+
longWork();
32+
}, 1000);
33+
34+
setTimeout(() => {
35+
longWork();
36+
}, 4000);

dev-packages/node-integration-tests/suites/anr/basic.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@ function longWork() {
3030
setTimeout(() => {
3131
longWork();
3232
}, 1000);
33+
34+
// Ensure we only send one event even with multiple blocking events
35+
setTimeout(() => {
36+
longWork();
37+
}, 4000);

dev-packages/node-integration-tests/suites/anr/test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ const ANR_EVENT_WITH_DEBUG_META: Event = {
101101
{
102102
type: 'sourcemap',
103103
debug_id: 'aaaaaaaa-aaaa-4aaa-aaaa-aaaaaaaaaa',
104-
code_file: expect.stringContaining('basic.'),
104+
code_file: expect.stringContaining('basic'),
105105
},
106106
],
107107
},
@@ -123,6 +123,14 @@ conditionalTest({ min: 16 })('should report ANR when event loop blocked', () =>
123123
.start(done);
124124
});
125125

126+
test('multiple events via maxAnrEvents', done => {
127+
createRunner(__dirname, 'basic-multiple.mjs')
128+
.withMockSentryServer()
129+
.expect({ event: ANR_EVENT_WITH_DEBUG_META })
130+
.expect({ event: ANR_EVENT_WITH_DEBUG_META })
131+
.start(done);
132+
});
133+
126134
test('blocked indefinitely', done => {
127135
createRunner(__dirname, 'indefinite.mjs').withMockSentryServer().expect({ event: ANR_EVENT }).start(done);
128136
});

0 commit comments

Comments
 (0)