Skip to content

Commit a01d6a8

Browse files
nicohrubecclaude
andauthored
test(node-core): Fix minute-boundary race in session-aggregate tests (#20437)
The SDK buckets sessions by minute-rounded timestamp. When a test's sequential requests run across a minute boundary, the payload splits across two `aggregates` buckets and the existing single-bucket assertion fails. To resolve this, this PR replaces the single bucket check with a sum across all returned buckets to ensure the total count is correct even if events are split across buckets. The same pattern exists in our `node-core` and `node` integration tests. Closes #20283 Closes #20436 Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 7b9ce98 commit a01d6a8

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)