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

Fix random failures in unit tests #371

Merged
merged 1 commit into from
Feb 11, 2025

Conversation

anfredette
Copy link
Contributor

@anfredette anfredette commented Feb 11, 2025

Failures were caused when the same randomly generated id was used for more than one program
in the fake bpfman client. Changed the code to use a deterministic incrementing ID.

Copy link

codecov bot commented Feb 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 28.13%. Comparing base (fc76814) to head (cffb2b8).
Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #371      +/-   ##
==========================================
+ Coverage   28.12%   28.13%   +0.01%     
==========================================
  Files         128      128              
  Lines       11207    11209       +2     
==========================================
+ Hits         3152     3154       +2     
  Misses       7773     7773              
  Partials      282      282              
Flag Coverage Δ
unittests 28.13% <100.00%> (+0.01%) ⬆️

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.

if _, ok := b.LoadRequests[id]; !ok {
break
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

can u avoid infinite loop and just have maxRetries and fail if its reached ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I figured someone wouldn't like the infinite loop :-). How about this new solution that doesn't use random numbers?

Failures were caused when the same random id was used for more than one
program in the fake bpfman client. Changed the code to use a
deterministic incrementing ID.

Signed-off-by: Andre Fredette <[email protected]>
@anfredette anfredette force-pushed the fix-bpfman-fake-client branch from 3573998 to cffb2b8 Compare February 11, 2025 20:10
func (b *BpfmanClientFake) Load(ctx context.Context, in *gobpfman.LoadRequest, opts ...grpc.CallOption) (*gobpfman.LoadResponse, error) {
id := rand.Intn(100)
currentID++
id := currentID
Copy link
Contributor

Choose a reason for hiding this comment

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

do u still need currentID ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you have a different solution in mind?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW, I've seen this issue for a long time. I.e., unit tests would fail sometimes, but when you run them again they would pass. It just started happening often enough when I started using more programs that it bothered me enough to figure out why.

Copy link
Contributor

Choose a reason for hiding this comment

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

i was just thinking of adding a cntr of 100 or 100 retries to get unused id from random instead of infinite loop

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understood what you were suggesting, and I think it would work, but I think this is better -- it's simpler and always unique because you remember the last ID and increment it for the next one.

I thought about doing it this way after I made the first change, but figured the previous way was good enough and didn't bother going back to change it.

Copy link
Contributor

Choose a reason for hiding this comment

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

sure I am fine either way was just answering ur question

@msherif1234
Copy link
Contributor

/LGTM

@mergify mergify bot merged commit 280fbaf into bpfman:main Feb 11, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants