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

[chore] apply some nits to contract_checker. #9543

Merged
merged 1 commit into from
Feb 16, 2024
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
28 changes: 11 additions & 17 deletions receiver/receivertest/contract_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func CheckConsumeContract(params CheckConsumeContractParams) {
}

func checkConsumeContractScenario(params CheckConsumeContractParams, decisionFunc func(ids idSet) error) {
consumer := &mockConsumer{t: params.T, consumeDecisionFunc: decisionFunc}
consumer := &mockConsumer{t: params.T, consumeDecisionFunc: decisionFunc, acceptedIDs: make(idSet), droppedIDs: make(idSet)}
ctx := context.Background()

// Create and start the receiver.
Expand All @@ -129,7 +129,7 @@ func checkConsumeContractScenario(params CheckConsumeContractParams, decisionFun

// Begin generating data to the receiver.

var generatedIDs idSet
generatedIDs := make(idSet)
var generatedIndex int64
var mux sync.Mutex
var wg sync.WaitGroup
Expand Down Expand Up @@ -224,40 +224,34 @@ func (ds idSet) compare(other idSet) (missingInOther, onlyInOther []UniqueIDAttr
}

// merge another set into this one and return a list of duplicate ids.
func (ds *idSet) merge(other idSet) (duplicates []UniqueIDAttrVal) {
if *ds == nil {
*ds = map[UniqueIDAttrVal]bool{}
}
func (ds idSet) merge(other idSet) (duplicates []UniqueIDAttrVal) {
for k, v := range other {
if _, ok := (*ds)[k]; ok {
if _, ok := ds[k]; ok {
duplicates = append(duplicates, k)
} else {
(*ds)[k] = v
ds[k] = v
}
}
return
}

// merge another set into this one and return a list of duplicate ids.
func (ds *idSet) mergeSlice(other []UniqueIDAttrVal) (duplicates []UniqueIDAttrVal) {
if *ds == nil {
*ds = map[UniqueIDAttrVal]bool{}
}
// mergeSlice merges another set into this one and return a list of duplicate ids.
func (ds idSet) mergeSlice(other []UniqueIDAttrVal) (duplicates []UniqueIDAttrVal) {
for _, id := range other {
if _, ok := (*ds)[id]; ok {
if _, ok := ds[id]; ok {
duplicates = append(duplicates, id)
} else {
(*ds)[id] = true
ds[id] = true
}
}
return
}

// union computes the union of this and another sets. A new set if created to return the result.
// Also returns a list of any duplicate ids found.
func (ds *idSet) union(other idSet) (union idSet, duplicates []UniqueIDAttrVal) {
func (ds idSet) union(other idSet) (union idSet, duplicates []UniqueIDAttrVal) {
union = map[UniqueIDAttrVal]bool{}
for k, v := range *ds {
for k, v := range ds {
union[k] = v
}
for k, v := range other {
Expand Down
Loading