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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package testutils
import (
"context"
"fmt"
"math/rand"

gobpfman "github.com/bpfman/bpfman/clients/gobpfman/v1"
grpc "google.golang.org/grpc"
Expand Down Expand Up @@ -55,8 +54,12 @@ func NewBpfmanClientFakeWithPrograms(programs map[int]*gobpfman.ListResponse_Lis
}
}

var currentID = 1000

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


b.LoadRequests[id] = in

b.Programs[id] = loadRequestToListResult(in, uint32(id))
Expand Down
Loading