From: Keith Randall Date: Mon, 8 Nov 2021 05:29:30 +0000 (-0800) Subject: internal/fmtsort: order channels in test in memory address order X-Git-Tag: go1.18beta1~455 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=6a9d81174e6c7d205fc189a1eac56212a723c40c;p=gostls13.git 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 Run-TryBot: Keith Randall Reviewed-by: Bryan C. Mills Reviewed-by: Cuong Manh Le --- diff --git a/src/internal/fmtsort/sort_test.go b/src/internal/fmtsort/sort_test.go index 5c4db1c5fa..ab063af5ba 100644 --- a/src/internal/fmtsort/sort_test.go +++ b/src/internal/fmtsort/sort_test.go @@ -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-- {