Skip to content

Commit 5e3960d

Browse files
committed
Do not sort before sending to the listener.
1 parent 980d2d9 commit 5e3960d

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

reader.go

-3
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,6 @@ func (r *Reader) run(cg *ConsumerGroup) {
311311
for _, partition := range partitions {
312312
assignedPartitions = append(assignedPartitions, partition.ID)
313313
}
314-
sort.Slice(assignedPartitions, func(i, j int) bool {
315-
return assignedPartitions[i] < assignedPartitions[j]
316-
})
317314
assignments = append(assignments, GroupMemberTopic{
318315
Topic: topic,
319316
Partitions: assignedPartitions,

reader_test.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net"
1111
"os"
1212
"reflect"
13+
"sort"
1314
"strconv"
1415
"sync"
1516
"testing"
@@ -891,7 +892,7 @@ func TestReaderConsumerGroup(t *testing.T) {
891892
}
892893
}
893894

894-
func TestAssignmentListener(t *testing.T) {
895+
func TestPartitionAssignmentListener(t *testing.T) {
895896
// It appears that some of the tests depend on all these tests being
896897
// run concurrently to pass... this is brittle and should be fixed
897898
// at some point.
@@ -917,6 +918,12 @@ func TestAssignmentListener(t *testing.T) {
917918
AssignmentListener: func(partitions []GroupMemberTopic) {
918919
lock.Lock()
919920
defer lock.Unlock()
921+
// we sort the received partitions for easier comparison
922+
for _, partition := range partitions {
923+
sort.Slice(partition.Partitions, func(i, j int) bool {
924+
return partition.Partitions[i] < partition.Partitions[j]
925+
})
926+
}
920927
assignments = append(assignments, partitions)
921928
},
922929
})

0 commit comments

Comments
 (0)