Skip to content

Commit f304811

Browse files
committed
Add tests
1 parent 7697d7b commit f304811

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
@@ -72,7 +72,7 @@ const ANR_EVENT_WITH_DEBUG_META: Event = {
7272
{
7373
type: 'sourcemap',
7474
debug_id: 'aaaaaaaa-aaaa-4aaa-aaaa-aaaaaaaaaa',
75-
code_file: expect.stringContaining('basic.'),
75+
code_file: expect.stringContaining('basic'),
7676
},
7777
],
7878
},
@@ -94,6 +94,14 @@ conditionalTest({ min: 16 })('should report ANR when event loop blocked', () =>
9494
.start(done);
9595
});
9696

97+
test('multiple events via maxAnrEvents', done => {
98+
createRunner(__dirname, 'basic-multiple.mjs')
99+
.withMockSentryServer()
100+
.expect({ event: ANR_EVENT_WITH_DEBUG_META })
101+
.expect({ event: ANR_EVENT_WITH_DEBUG_META })
102+
.start(done);
103+
});
104+
97105
test('blocked indefinitely', done => {
98106
createRunner(__dirname, 'indefinite.mjs').withMockSentryServer().expect({ event: ANR_EVENT }).start(done);
99107
});

0 commit comments

Comments
 (0)