Skip to content

Commit

Permalink
[chore] apply some nits to contract_checker. Fix a comment and don't …
Browse files Browse the repository at this point in the history
…mix receiver functions with and without pointers
  • Loading branch information
atoulme committed Feb 9, 2024
1 parent 9553bfe commit e757c13
Showing 1 changed file with 11 additions and 17 deletions.
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

0 comments on commit e757c13

Please sign in to comment.