Skip to content

NH-132896: increase test coverage#254

Open
xuan-cao-swi wants to merge 10 commits intomainfrom
NH-132896
Open

NH-132896: increase test coverage#254
xuan-cao-swi wants to merge 10 commits intomainfrom
NH-132896

Conversation

@xuan-cao-swi
Copy link
Contributor

Description

Test (if applicable)

Copy link
Contributor

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

RuboCop found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@xuan-cao-swi xuan-cao-swi marked this pull request as ready for review March 20, 2026 02:47
@xuan-cao-swi xuan-cao-swi requested review from a team as code owners March 20, 2026 02:47
@cheempz
Copy link
Contributor

cheempz commented Mar 24, 2026

@xuan-cao-swi any way to easily see the coverage info? Quick check there seem to be GHA integrations available.

@xuan-cao-swi
Copy link
Contributor Author

@xuan-cao-swi any way to easily see the coverage info? Quick check there seem to be GHA integrations available.

Yeah, I integrated the codecov.io

Copy link
Contributor

@cheempz cheempz left a comment

Choose a reason for hiding this comment

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

Overall i like the improvements on test description and coverage, but from spot-checking what tests are actually doing, there are gaps between what descriptions say are being tested and actual setup/assertions.

require './lib/solarwinds_apm/api'

describe 'API::OpenTelemetry#in_span delegation to OpenTelemetry tracer' do
it 'returns nil and warns when block is nil' do
Copy link
Contributor

Choose a reason for hiding this comment

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

i see the return nil is asserted. how is the "warns when block is nil" tested?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added assertion that logger.warn will be called.

assert_nil result
end

it 'calls OpenTelemetry tracer in_span with a block' do
Copy link
Contributor

Choose a reason for hiding this comment

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

How is the "calls OTel tracer" being checed in this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The name is misleading (and updated). It should just check everything works fine if block is given.


trace = SolarWindsAPM::API.current_trace_info
result = trace.for_log
assert_includes result, 'trace_id='
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be better to assert that there's something after the = sign for these fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@propagator.inject(carrier, context: context)

assert carrier.key?('x-trace')
assert_includes carrier['x-trace'], '00-'
Copy link
Contributor

Choose a reason for hiding this comment

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

Any way to assert the value of x-trace against the context that was provided?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

carrier = {}
@propagator.inject(carrier, context: context)

assert carrier.key?('x-trace-options-response')
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question on asserting the value of the header.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated


# Second call should skip due to not expired
params = make_sample_params
sampler.should_sample?(params)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure how this is asserting loop_check is skipped, and similar question for next test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Once the loop_check is skipped, the @expiry should stay the same.
Updated the test case that assert the @expiry

SolarWindsAPM::OTelConfig.class_variable_get(:@@config)[:metrics_processor] = original_proc
end

it 'sets transaction name within a valid span context' do
Copy link
Contributor

Choose a reason for hiding this comment

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

This test implies it checks a transaction name is actually set, but there is no such assertion that i can see. Like the previous tests it's only checking the response from the call to set_transaction_name(). Also, since previous tests don't set up a valid span context, they might not really be testing the scenarios they claim to test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated both test case that provide invalid span context and valid one as part of test case

@xuan-cao-swi xuan-cao-swi requested a review from cheempz March 26, 2026 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants