Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test][WIP] Unit test for OTLP receiver in jaeger-v1 #6541

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

chahatsagarmain
Copy link
Contributor

Which problem is this PR solving?

Description of the changes

  • Added unit test

How was this change tested?

Checklist

Signed-off-by: chahatsagarmain <[email protected]>
@chahatsagarmain chahatsagarmain requested a review from a team as a code owner January 13, 2025 19:51
@chahatsagarmain chahatsagarmain marked this pull request as draft January 13, 2025 19:51
Copy link

codecov bot commented Jan 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.23%. Comparing base (0b5f8b1) to head (e1d95b2).
Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6541      +/-   ##
==========================================
- Coverage   96.25%   96.23%   -0.02%     
==========================================
  Files         372      373       +1     
  Lines       21371    21406      +35     
==========================================
+ Hits        20570    20600      +30     
- Misses        610      614       +4     
- Partials      191      192       +1     
Flag Coverage Δ
badger_v1 10.64% <ø> (-0.02%) ⬇️
badger_v2 2.77% <ø> (-0.01%) ⬇️
cassandra-4.x-v1-manual 16.58% <ø> (+0.03%) ⬆️
cassandra-4.x-v2-auto 2.71% <ø> (-0.01%) ⬇️
cassandra-4.x-v2-manual 2.71% <ø> (-0.01%) ⬇️
cassandra-5.x-v1-manual 16.58% <ø> (+0.03%) ⬆️
cassandra-5.x-v2-auto 2.71% <ø> (-0.01%) ⬇️
cassandra-5.x-v2-manual 2.71% <ø> (-0.01%) ⬇️
elasticsearch-6.x-v1 20.36% <ø> (+0.03%) ⬆️
elasticsearch-7.x-v1 20.44% <ø> (+0.03%) ⬆️
elasticsearch-8.x-v1 20.60% <ø> (+0.03%) ⬆️
elasticsearch-8.x-v2 2.76% <ø> (-0.11%) ⬇️
grpc_v1 12.15% <ø> (-0.03%) ⬇️
grpc_v2 9.02% <ø> (-0.03%) ⬇️
kafka-3.x-v1 10.32% <ø> (-0.02%) ⬇️
kafka-3.x-v2 2.77% <ø> (-0.01%) ⬇️
memory_v2 2.77% <ø> (-0.01%) ⬇️
opensearch-1.x-v1 20.49% <ø> (+0.04%) ⬆️
opensearch-2.x-v1 20.49% <ø> (+0.04%) ⬆️
opensearch-2.x-v2 2.77% <ø> (-0.01%) ⬇️
tailsampling-processor 0.51% <ø> (-0.01%) ⬇️
unittests 95.09% <ø> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: chahatsagarmain <[email protected]>
@yurishkuro
Copy link
Member

dependent PR was merged

chahatsagarmain and others added 3 commits January 15, 2025 22:29
Signed-off-by: chahatsagarmain <[email protected]>
Signed-off-by: chahatsagarmain <[email protected]>

if equal {
rSpan := td.ResourceSpans().At(0)
equal = rSpan.ScopeSpans().Len() == 1 &&
Copy link
Member

Choose a reason for hiding this comment

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

you don't need so complicated checks, it's ok in the test to just assume that you can directly navigate to the span (and let it panic if not)

rSpan.ScopeSpans().At(0).Spans().At(0).SpanID() == byteId
}
if !equal {
t.Error("Traces don't match expected structure")
Copy link
Member

Choose a reason for hiding this comment

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

this is not a common pattern to perform validation inside of the mock implementation. You can simply store the passed value in an outside variable and then perform assertion in the main body of the test.

)
require.NoError(t, err)
defer spanProcessor.Close()
logger, _ := testutils.NewLogger()
Copy link
Member

Choose a reason for hiding this comment

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

if you don't need to inspect logger results (you're ignoring the buf return value), use zaptest.NewLogger(t) or zap.NewNop() instead

Signed-off-by: chahatsagarmain <[email protected]>
Comment on lines 851 to 852
var receivedTraces ptrace.Traces
var mu sync.Mutex
Copy link
Member

Choose a reason for hiding this comment

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

you can use atomic.Pointer instead of two vars

@yurishkuro yurishkuro added the changelog:test Change that's adding missing tests or correcting existing tests label Jan 18, 2025
Signed-off-by: chahatsagarmain <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:test Change that's adding missing tests or correcting existing tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add e2e unit test for OTLP receiver in jaeger-v1
2 participants