Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as crypto from 'crypto';
import * as path from 'path';
import * as url from 'url';
import { setupOtel } from '../../utils/setupOtel.js';
import { waitForDebuggerReady } from '@sentry-internal/test-utils';

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

Expand Down Expand Up @@ -32,6 +33,6 @@ function longWork() {
}
}

setTimeout(() => {
waitForDebuggerReady(() => {
longWork();
}, 1000);
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as Sentry from '@sentry/node-core';
import * as assert from 'assert';
import * as crypto from 'crypto';
import { setupOtel } from '../../utils/setupOtel.js';
import { waitForDebuggerReady } from '@sentry-internal/test-utils';

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

Expand All @@ -28,10 +29,11 @@ function longWork() {
}
}

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

setTimeout(() => {
longWork();
}, 4000);
// Second blocking event for maxAnrEvents test
setTimeout(() => {
longWork();
}, 2000);
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const assert = require('assert');

const Sentry = require('@sentry/node-core');
const { setupOtel } = require('../../utils/setupOtel.js');
const { waitForDebuggerReady } = require('@sentry-internal/test-utils');

setTimeout(() => {
process.exit();
Expand All @@ -27,6 +28,6 @@ function longWork() {
}
}

setTimeout(() => {
waitForDebuggerReady(() => {
longWork();
}, 1000);
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const assert = require('assert');

const Sentry = require('@sentry/node-core');
const { setupOtel } = require('../../utils/setupOtel.js');
const { waitForDebuggerReady } = require('@sentry-internal/test-utils');

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

Expand All @@ -29,6 +30,6 @@ function longWork() {
}
}

setTimeout(() => {
waitForDebuggerReady(() => {
longWork();
}, 1000);
});
13 changes: 7 additions & 6 deletions dev-packages/node-core-integration-tests/suites/anr/basic.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as Sentry from '@sentry/node-core';
import * as assert from 'assert';
import * as crypto from 'crypto';
import { setupOtel } from '../../utils/setupOtel.js';
import { waitForDebuggerReady } from '@sentry-internal/test-utils';

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

Expand All @@ -28,11 +29,11 @@ function longWork() {
}
}

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

// Ensure we only send one event even with multiple blocking events
setTimeout(() => {
longWork();
}, 4000);
// Ensure we only send one event even with multiple blocking events
setTimeout(() => {
longWork();
}, 2000);
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const assert = require('assert');

const Sentry = require('@sentry/node-core');
const { setupOtel } = require('../../utils/setupOtel.js');
const { waitForDebuggerReady } = require('@sentry-internal/test-utils');

setTimeout(() => {
process.exit();
Expand All @@ -28,6 +29,6 @@ function longWork() {
}
}

setTimeout(() => {
waitForDebuggerReady(() => {
longWork();
}, 1000);
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as Sentry from '@sentry/node-core';
import * as assert from 'assert';
import * as crypto from 'crypto';
import { setupOtel } from '../../utils/setupOtel.js';
import { waitForDebuggerReady } from '@sentry-internal/test-utils';

setTimeout(() => {
process.exit();
Expand All @@ -27,6 +28,6 @@ function longWork() {
}
}

setTimeout(() => {
waitForDebuggerReady(() => {
longWork();
}, 1000);
});
5 changes: 3 additions & 2 deletions dev-packages/node-integration-tests/suites/anr/app-path.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as assert from 'assert';
import * as crypto from 'crypto';
import * as path from 'path';
import * as url from 'url';
import { waitForDebuggerReady } from '@sentry-internal/test-utils';

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

Expand All @@ -29,6 +30,6 @@ function longWork() {
}
}

setTimeout(() => {
waitForDebuggerReady(() => {
longWork();
}, 1000);
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as Sentry from '@sentry/node';
import * as assert from 'assert';
import * as crypto from 'crypto';
import { waitForDebuggerReady } from '@sentry-internal/test-utils';

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

Expand All @@ -25,10 +26,11 @@ function longWork() {
}
}

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

setTimeout(() => {
longWork();
}, 4000);
// Second blocking event for maxAnrEvents test
setTimeout(() => {
longWork();
}, 2000);
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const crypto = require('crypto');
const assert = require('assert');

const Sentry = require('@sentry/node');
const { waitForDebuggerReady } = require('@sentry-internal/test-utils');

setTimeout(() => {
process.exit();
Expand All @@ -24,6 +25,6 @@ function longWork() {
}
}

setTimeout(() => {
waitForDebuggerReady(() => {
longWork();
}, 1000);
});
5 changes: 3 additions & 2 deletions dev-packages/node-integration-tests/suites/anr/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const crypto = require('crypto');
const assert = require('assert');

const Sentry = require('@sentry/node');
const { waitForDebuggerReady } = require('@sentry-internal/test-utils');

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

Expand All @@ -26,6 +27,6 @@ function longWork() {
}
}

setTimeout(() => {
waitForDebuggerReady(() => {
longWork();
}, 1000);
});
13 changes: 7 additions & 6 deletions dev-packages/node-integration-tests/suites/anr/basic.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as Sentry from '@sentry/node';
import * as assert from 'assert';
import * as crypto from 'crypto';
import { waitForDebuggerReady } from '@sentry-internal/test-utils';

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

Expand All @@ -25,11 +26,11 @@ function longWork() {
}
}

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

// Ensure we only send one event even with multiple blocking events
setTimeout(() => {
longWork();
}, 4000);
// Ensure we only send one event even with multiple blocking events
setTimeout(() => {
longWork();
}, 2000);
});
5 changes: 3 additions & 2 deletions dev-packages/node-integration-tests/suites/anr/forked.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const crypto = require('crypto');
const assert = require('assert');

const Sentry = require('@sentry/node');
const { waitForDebuggerReady } = require('@sentry-internal/test-utils');

setTimeout(() => {
process.exit();
Expand All @@ -25,6 +26,6 @@ function longWork() {
}
}

setTimeout(() => {
waitForDebuggerReady(() => {
longWork();
}, 1000);
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as Sentry from '@sentry/node';
import * as assert from 'assert';
import * as crypto from 'crypto';
import { waitForDebuggerReady } from '@sentry-internal/test-utils';

setTimeout(() => {
process.exit();
Expand All @@ -24,6 +25,6 @@ function longWork() {
}
}

setTimeout(() => {
waitForDebuggerReady(() => {
longWork();
}, 1000);
});
19 changes: 19 additions & 0 deletions dev-packages/test-utils/src/anr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as inspector from 'inspector';

/**
* Waits for the ANR worker's debugger to be fully ready before executing callback.
*
* The ANR worker creates an InspectorSession and connects to the main thread's debugger.
* We poll inspector.url() to detect when the debugger is active, then wait 200ms for the
* async session setup to complete.
*/
export function waitForDebuggerReady(cb: () => void): void {
const check = (): void => {
if (inspector.url()) {
setTimeout(cb, 200);
} else {
setImmediate(check);
}
};
setImmediate(check);
}
2 changes: 2 additions & 0 deletions dev-packages/test-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ export type { CDPClientOptions } from './cdp-client';

export { MemoryProfiler } from './memory-profiler';
export type { MemoryProfilerOptions, SnapshotStats, SnapshotComparisonResult } from './memory-profiler';

export { waitForDebuggerReady } from './anr';
Loading