Skip to content

Commit

Permalink
sort the slice for deterministic order in unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: rahulii <[email protected]>
  • Loading branch information
rahulii committed Jul 31, 2024
1 parent 7b97071 commit 3a2c542
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/reconciler/parallel/parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package parallel
import (
"context"
"fmt"
"sort"

"go.uber.org/zap"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -467,6 +468,11 @@ func (r *Reconciler) prepareIngressChannelEventpolicies(p *v1.Parallel, ingressC
return nil, nil
}

// sort the event policies by name to ensure deterministic order.
sort.Slice(applyingEventPoliciesForParallel, func(i, j int) bool {
return applyingEventPoliciesForParallel[i].Name < applyingEventPoliciesForParallel[j].Name
})

ingressChannelEventPolicies := make([]*eventingv1alpha1.EventPolicy, 0, len(applyingEventPoliciesForParallel))
for _, eventPolicy := range applyingEventPoliciesForParallel {
ingressChannelEventPolicies = append(ingressChannelEventPolicies, resources.MakeEventPolicyForParallelIngressChannel(p, ingressChannel, eventPolicy))
Expand Down

0 comments on commit 3a2c542

Please sign in to comment.