Skip to content

Commit ba558eb

Browse files
nicohrubecclaude
andcommitted
test(node-core): Fix minute-boundary race in session-aggregate tests
The SDK buckets session counts by minute-rounded timestamp (see `packages/node-core/src/integrations/http/httpServerIntegration.ts` lines 290-292). When the test's sequential requests straddle a minute boundary, the emitted payload splits across two aggregate buckets and the existing `aggregates: [{...}]` assertion fails — a pure timing race, not a code bug. Replace the hard-coded single-bucket assertion with an inline reduce that sums `exited`/`errored`/`crashed` across all returned buckets and asserts on the totals, matching the SDK's real behaviour. Applies to all 5 session-aggregate integration tests (2 in node-core, 3 in node). Two of them already flake (#20283, #20436); the other three share the same pattern and are preventively fixed. Closes #20283 Closes #20436 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 617fede commit ba558eb

5 files changed

Lines changed: 55 additions & 39 deletions

File tree

  • dev-packages
    • node-core-integration-tests/suites/sessions
    • node-integration-tests/suites/sessions

dev-packages/node-core-integration-tests/suites/sessions/errored-session-aggregate/test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ test('should aggregate successful, crashed and erroneous sessions', async () =>
1010
.ignore('transaction', 'event')
1111
.unignore('sessions')
1212
.expect({
13-
sessions: {
14-
aggregates: [
15-
{
16-
started: expect.any(String),
17-
exited: 2,
18-
errored: 1,
19-
},
20-
],
13+
sessions: agg => {
14+
// Sessions are bucketed by minute; tolerate splits across a minute boundary by summing.
15+
const totals = agg.aggregates.reduce(
16+
(acc, b) => ({
17+
exited: acc.exited + (b.exited ?? 0),
18+
errored: acc.errored + (b.errored ?? 0),
19+
crashed: acc.crashed + (b.crashed ?? 0),
20+
}),
21+
{ exited: 0, errored: 0, crashed: 0 },
22+
);
23+
expect(totals).toEqual({ exited: 2, errored: 1, crashed: 0 });
2124
},
2225
})
2326
.start();

dev-packages/node-core-integration-tests/suites/sessions/exited-session-aggregate/test.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ test('should aggregate successful sessions', async () => {
1010
.ignore('transaction', 'event')
1111
.unignore('sessions')
1212
.expect({
13-
sessions: {
14-
aggregates: [
15-
{
16-
started: expect.any(String),
17-
exited: 3,
18-
},
19-
],
13+
sessions: agg => {
14+
// Sessions are bucketed by minute; tolerate splits across a minute boundary by summing.
15+
const totals = agg.aggregates.reduce(
16+
(acc, b) => ({
17+
exited: acc.exited + (b.exited ?? 0),
18+
errored: acc.errored + (b.errored ?? 0),
19+
crashed: acc.crashed + (b.crashed ?? 0),
20+
}),
21+
{ exited: 0, errored: 0, crashed: 0 },
22+
);
23+
expect(totals).toEqual({ exited: 3, errored: 0, crashed: 0 });
2024
},
2125
})
2226
.start();

dev-packages/node-integration-tests/suites/sessions/crashed-session-aggregate/test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ test('should aggregate successful and crashed sessions', async () => {
1010
.ignore('transaction', 'event')
1111
.unignore('sessions')
1212
.expect({
13-
sessions: {
14-
aggregates: [
15-
{
16-
started: expect.any(String),
17-
exited: 2,
18-
crashed: 1,
19-
},
20-
],
13+
sessions: agg => {
14+
// Sessions are bucketed by minute; tolerate splits across a minute boundary by summing.
15+
const totals = agg.aggregates.reduce(
16+
(acc, b) => ({
17+
exited: acc.exited + (b.exited ?? 0),
18+
errored: acc.errored + (b.errored ?? 0),
19+
crashed: acc.crashed + (b.crashed ?? 0),
20+
}),
21+
{ exited: 0, errored: 0, crashed: 0 },
22+
);
23+
expect(totals).toEqual({ exited: 2, errored: 0, crashed: 1 });
2124
},
2225
})
2326
.start();

dev-packages/node-integration-tests/suites/sessions/errored-session-aggregate/test.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ test('should aggregate successful, crashed and erroneous sessions', async () =>
1010
.ignore('transaction', 'event')
1111
.unignore('sessions')
1212
.expect({
13-
sessions: {
14-
aggregates: [
15-
{
16-
started: expect.any(String),
17-
exited: 1,
18-
crashed: 1,
19-
errored: 1,
20-
},
21-
],
13+
sessions: agg => {
14+
// Sessions are bucketed by minute; tolerate splits across a minute boundary by summing.
15+
const totals = agg.aggregates.reduce(
16+
(acc, b) => ({
17+
exited: acc.exited + (b.exited ?? 0),
18+
errored: acc.errored + (b.errored ?? 0),
19+
crashed: acc.crashed + (b.crashed ?? 0),
20+
}),
21+
{ exited: 0, errored: 0, crashed: 0 },
22+
);
23+
expect(totals).toEqual({ exited: 1, errored: 1, crashed: 1 });
2224
},
2325
})
2426
.start();

dev-packages/node-integration-tests/suites/sessions/exited-session-aggregate/test.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ test('should aggregate successful sessions', async () => {
1010
.ignore('transaction', 'event')
1111
.unignore('sessions')
1212
.expect({
13-
sessions: {
14-
aggregates: [
15-
{
16-
started: expect.any(String),
17-
exited: 3,
18-
},
19-
],
13+
sessions: agg => {
14+
// Sessions are bucketed by minute; tolerate splits across a minute boundary by summing.
15+
const totals = agg.aggregates.reduce(
16+
(acc, b) => ({
17+
exited: acc.exited + (b.exited ?? 0),
18+
errored: acc.errored + (b.errored ?? 0),
19+
crashed: acc.crashed + (b.crashed ?? 0),
20+
}),
21+
{ exited: 0, errored: 0, crashed: 0 },
22+
);
23+
expect(totals).toEqual({ exited: 3, errored: 0, crashed: 0 });
2024
},
2125
})
2226
.start();

0 commit comments

Comments
 (0)