Skip to content

test: Added assertSegmentDuration and missing segment duration tests#3875

Draft
amychisholm03 wants to merge 1 commit intonewrelic:mainfrom
amychisholm03:NR-3852/assert-segment-duration
Draft

test: Added assertSegmentDuration and missing segment duration tests#3875
amychisholm03 wants to merge 1 commit intonewrelic:mainfrom
amychisholm03:NR-3852/assert-segment-duration

Conversation

@amychisholm03
Copy link
Copy Markdown
Contributor

@amychisholm03 amychisholm03 commented Mar 30, 2026

Description

WIP: Not ready for full review yet, just testing CI.

As we migrate our instrumentation to use the tracing channel subscribers, we need a way to be able to check if our segment durations are expected (e.g. not ending immediately). However, previous attempts have been extremely flaky because our CI has much more constrained environments vs our PCs running locally.

This PR adds a new custom assertion, assertSegmentDuration and adds it to tests whose packages we have migrated over and need segment duration timing tests (packages like mysql2 with "easy" way to assert time like sleep(2) were excluded). In an attempt to combat flakiness, getDefaultThreshold in assert-segment-duration.js comes up with a percentage threshold (as a float) based on the number of CPU cores available. The numbers are basically arbitrary but seem okay enough to consistently pass.

Some tests, like memcached.test.js, are really really flaky so they have a high threshold supplied instead of using the default.

How to Test

npm run versioned:major

Related Issues

Closes #3862

Copy link
Copy Markdown
Member

@bizob2828 bizob2828 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see the CI failed and the actual duration vs record durations seem off like our timing is wrong

@amychisholm03 amychisholm03 force-pushed the NR-3852/assert-segment-duration branch from 39495ba to 46c9bca Compare April 9, 2026 19:27
@amychisholm03 amychisholm03 force-pushed the NR-3852/assert-segment-duration branch from 065269b to 0e14911 Compare April 9, 2026 19:33
@amychisholm03
Copy link
Copy Markdown
Contributor Author

i see the CI failed and the actual duration vs record durations seem off like our timing is wrong

Yeah, there are some large time differences. However, the failures are different packages every time, so I don't think it has to deal with how we are timing the actualTime, but just general flakiness for some reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs PR Review

Development

Successfully merging this pull request may close these issues.

Add a assertSegmentDuration function in custom assertions

3 participants