1
0
mirror of https://github.com/golang/go synced 2024-09-29 20:14:29 -06:00

internal/fmtsort: order channels in test in memory address order

Kind of a kludge, but it makes the test work reliably.

Fixes #49431

Change-Id: Ic2a075ba02f80ea7efcc1b3f0f5a43649e87c0d8
Reviewed-on: https://go-review.googlesource.com/c/go/+/361918
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
Keith Randall 2021-11-07 21:29:30 -08:00
parent 7bda349c17
commit 6a9d81174e

View File

@ -9,6 +9,7 @@ import (
"internal/fmtsort"
"math"
"reflect"
"sort"
"strings"
"testing"
"unsafe"
@ -188,9 +189,19 @@ func sprintKey(key reflect.Value) string {
var (
ints [3]int
chans = [3]chan int{make(chan int), make(chan int), make(chan int)}
chans = makeChans()
)
func makeChans() []chan int {
cs := []chan int{make(chan int), make(chan int), make(chan int)}
// Order channels by address. See issue #49431.
// TODO: pin these pointers once pinning is available (#46787).
sort.Slice(cs, func(i, j int) bool {
return uintptr(reflect.ValueOf(cs[i]).UnsafePointer()) < uintptr(reflect.ValueOf(cs[j]).UnsafePointer())
})
return cs
}
func pointerMap() map[*int]string {
m := make(map[*int]string)
for i := 2; i >= 0; i-- {