Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timfish committed Dec 12, 2024
1 parent 7697d7b commit f304811
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
36 changes: 36 additions & 0 deletions dev-packages/node-integration-tests/suites/anr/basic-multiple.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as assert from 'assert';
import * as crypto from 'crypto';

import * as Sentry from '@sentry/node';

global._sentryDebugIds = { [new Error().stack]: 'aaaaaaaa-aaaa-4aaa-aaaa-aaaaaaaaaa' };

setTimeout(() => {
process.exit();
}, 10000);

Sentry.init({
dsn: process.env.SENTRY_DSN,
release: '1.0',
autoSessionTracking: false,
integrations: [Sentry.anrIntegration({ captureStackTrace: true, anrThreshold: 100, maxAnrEvents: 2 })],
});

Sentry.setUser({ email: '[email protected]' });
Sentry.addBreadcrumb({ message: 'important message!' });

function longWork() {
for (let i = 0; i < 20; i++) {
const salt = crypto.randomBytes(128).toString('base64');
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
assert.ok(hash);
}
}

setTimeout(() => {
longWork();
}, 1000);

setTimeout(() => {
longWork();
}, 4000);
5 changes: 5 additions & 0 deletions dev-packages/node-integration-tests/suites/anr/basic.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ function longWork() {
setTimeout(() => {
longWork();
}, 1000);

// Ensure we only send one event even with multiple blocking events
setTimeout(() => {
longWork();
}, 4000);
10 changes: 9 additions & 1 deletion dev-packages/node-integration-tests/suites/anr/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const ANR_EVENT_WITH_DEBUG_META: Event = {
{
type: 'sourcemap',
debug_id: 'aaaaaaaa-aaaa-4aaa-aaaa-aaaaaaaaaa',
code_file: expect.stringContaining('basic.'),
code_file: expect.stringContaining('basic'),
},
],
},
Expand All @@ -94,6 +94,14 @@ conditionalTest({ min: 16 })('should report ANR when event loop blocked', () =>
.start(done);
});

test('multiple events via maxAnrEvents', done => {
createRunner(__dirname, 'basic-multiple.mjs')
.withMockSentryServer()
.expect({ event: ANR_EVENT_WITH_DEBUG_META })
.expect({ event: ANR_EVENT_WITH_DEBUG_META })
.start(done);
});

test('blocked indefinitely', done => {
createRunner(__dirname, 'indefinite.mjs').withMockSentryServer().expect({ event: ANR_EVENT }).start(done);
});
Expand Down

0 comments on commit f304811

Please sign in to comment.