Skip to content

Commit

Permalink
Do not sort before sending to the listener.
Browse files Browse the repository at this point in the history
  • Loading branch information
nachogiljaldo committed Sep 11, 2024
1 parent 980d2d9 commit 5e3960d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 0 additions & 3 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,6 @@ func (r *Reader) run(cg *ConsumerGroup) {
for _, partition := range partitions {
assignedPartitions = append(assignedPartitions, partition.ID)
}
sort.Slice(assignedPartitions, func(i, j int) bool {
return assignedPartitions[i] < assignedPartitions[j]
})
assignments = append(assignments, GroupMemberTopic{
Topic: topic,
Partitions: assignedPartitions,
Expand Down
9 changes: 8 additions & 1 deletion reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net"
"os"
"reflect"
"sort"
"strconv"
"sync"
"testing"
Expand Down Expand Up @@ -891,7 +892,7 @@ func TestReaderConsumerGroup(t *testing.T) {
}
}

func TestAssignmentListener(t *testing.T) {
func TestPartitionAssignmentListener(t *testing.T) {
// It appears that some of the tests depend on all these tests being
// run concurrently to pass... this is brittle and should be fixed
// at some point.
Expand All @@ -917,6 +918,12 @@ func TestAssignmentListener(t *testing.T) {
AssignmentListener: func(partitions []GroupMemberTopic) {
lock.Lock()
defer lock.Unlock()
// we sort the received partitions for easier comparison
for _, partition := range partitions {
sort.Slice(partition.Partitions, func(i, j int) bool {
return partition.Partitions[i] < partition.Partitions[j]
})
}
assignments = append(assignments, partitions)
},
})
Expand Down

0 comments on commit 5e3960d

Please sign in to comment.