package runtime_test
import (
- "reflect"
"runtime"
+ "slices"
"strings"
"testing"
)
}
got = append(got, frame.Function)
}
- if !reflect.DeepEqual(want, got) {
+ if !slices.Equal(want, got) {
t.Fatalf("wanted %v, got %v", want, got)
}
}
package runtime_test
import (
- "reflect"
"runtime"
+ "slices"
"testing"
)
t.Fatal("expected panic")
}
want := []int{4, 2, 1}
- if !reflect.DeepEqual(want, list) {
+ if !slices.Equal(want, list) {
t.Fatalf("wanted %v, got %v", want, list)
}
m[0] = append(m[0], a...)
want := []int{12345, 67890, 123, 456, 7, 8, 9, 0}
- if got := m[0]; !reflect.DeepEqual(got, want) {
+ if got := m[0]; !slices.Equal(got, want) {
t.Errorf("got %v, want %v", got, want)
}
}
first := ord()
ok := false
for try := 0; try < 100; try++ {
- if !reflect.DeepEqual(first, ord()) {
+ if !slices.Equal(first, ord()) {
ok = true
break
}
"os"
"regexp"
"runtime/metrics"
- "sort"
+ "slices"
"strings"
"testing"
_ "unsafe"
}
names := runtime_readMetricNames()
- sort.Strings(names)
+ slices.Sort(names)
samples := make([]metrics.Sample, len(names))
for i, name := range names {
samples[i].Name = name
checkUint64(t, "/gc/heap/frees:objects", frees, mstats.Frees-tinyAllocs)
// Verify that /gc/pauses:seconds is a copy of /sched/pauses/total/gc:seconds
- if !reflect.DeepEqual(gcPauses.Buckets, schedPausesTotalGC.Buckets) {
+ if !slices.Equal(gcPauses.Buckets, schedPausesTotalGC.Buckets) {
t.Errorf("/gc/pauses:seconds buckets %v do not match /sched/pauses/total/gc:seconds buckets %v", gcPauses.Buckets, schedPausesTotalGC.Counts)
}
- if !reflect.DeepEqual(gcPauses.Counts, schedPausesTotalGC.Counts) {
+ if !slices.Equal(gcPauses.Counts, schedPausesTotalGC.Counts) {
t.Errorf("/gc/pauses:seconds counts %v do not match /sched/pauses/total/gc:seconds counts %v", gcPauses.Counts, schedPausesTotalGC.Counts)
}
}
import (
"context"
"reflect"
- "sort"
+ "slices"
+ "strings"
"testing"
)
ls = append(ls, label{key, value})
return true
})
- sort.Sort(labelSorter(ls))
+ slices.SortFunc(ls, func(a, b label) int { return strings.Compare(a.key, b.key) })
return ls
}
-type labelSorter []label
-
-func (s labelSorter) Len() int { return len(s) }
-func (s labelSorter) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
-func (s labelSorter) Less(i, j int) bool { return s[i].key < s[j].key }
-
func TestContextLabels(t *testing.T) {
// Background context starts with no labels.
ctx := context.Background()
import (
"context"
"fmt"
- "reflect"
+ "maps"
"testing"
)
sync := make(chan struct{})
wantLabels := map[string]string{}
- if gotLabels := getProfLabel(); !reflect.DeepEqual(gotLabels, wantLabels) {
+ if gotLabels := getProfLabel(); !maps.Equal(gotLabels, wantLabels) {
t.Errorf("Expected parent goroutine's profile labels to be empty before test, got %v", gotLabels)
}
go func() {
- if gotLabels := getProfLabel(); !reflect.DeepEqual(gotLabels, wantLabels) {
+ if gotLabels := getProfLabel(); !maps.Equal(gotLabels, wantLabels) {
t.Errorf("Expected child goroutine's profile labels to be empty before test, got %v", gotLabels)
}
sync <- struct{}{}
wantLabels = map[string]string{"key": "value"}
ctx := WithLabels(context.Background(), Labels("key", "value"))
SetGoroutineLabels(ctx)
- if gotLabels := getProfLabel(); !reflect.DeepEqual(gotLabels, wantLabels) {
+ if gotLabels := getProfLabel(); !maps.Equal(gotLabels, wantLabels) {
t.Errorf("parent goroutine's profile labels: got %v, want %v", gotLabels, wantLabels)
}
go func() {
- if gotLabels := getProfLabel(); !reflect.DeepEqual(gotLabels, wantLabels) {
+ if gotLabels := getProfLabel(); !maps.Equal(gotLabels, wantLabels) {
t.Errorf("child goroutine's profile labels: got %v, want %v", gotLabels, wantLabels)
}
sync <- struct{}{}
wantLabels = map[string]string{}
ctx = context.Background()
SetGoroutineLabels(ctx)
- if gotLabels := getProfLabel(); !reflect.DeepEqual(gotLabels, wantLabels) {
+ if gotLabels := getProfLabel(); !maps.Equal(gotLabels, wantLabels) {
t.Errorf("Expected parent goroutine's profile labels to be empty, got %v", gotLabels)
}
go func() {
- if gotLabels := getProfLabel(); !reflect.DeepEqual(gotLabels, wantLabels) {
+ if gotLabels := getProfLabel(); !maps.Equal(gotLabels, wantLabels) {
t.Errorf("Expected child goroutine's profile labels to be empty, got %v", gotLabels)
}
sync <- struct{}{}
func TestDo(t *testing.T) {
wantLabels := map[string]string{}
- if gotLabels := getProfLabel(); !reflect.DeepEqual(gotLabels, wantLabels) {
+ if gotLabels := getProfLabel(); !maps.Equal(gotLabels, wantLabels) {
t.Errorf("Expected parent goroutine's profile labels to be empty before Do, got %v", gotLabels)
}
Do(context.Background(), Labels("key1", "value1", "key2", "value2"), func(ctx context.Context) {
wantLabels := map[string]string{"key1": "value1", "key2": "value2"}
- if gotLabels := getProfLabel(); !reflect.DeepEqual(gotLabels, wantLabels) {
+ if gotLabels := getProfLabel(); !maps.Equal(gotLabels, wantLabels) {
t.Errorf("parent goroutine's profile labels: got %v, want %v", gotLabels, wantLabels)
}
sync := make(chan struct{})
go func() {
wantLabels := map[string]string{"key1": "value1", "key2": "value2"}
- if gotLabels := getProfLabel(); !reflect.DeepEqual(gotLabels, wantLabels) {
+ if gotLabels := getProfLabel(); !maps.Equal(gotLabels, wantLabels) {
t.Errorf("child goroutine's profile labels: got %v, want %v", gotLabels, wantLabels)
}
sync <- struct{}{}
})
wantLabels = map[string]string{}
- if gotLabels := getProfLabel(); !reflect.DeepEqual(gotLabels, wantLabels) {
+ if gotLabels := getProfLabel(); !maps.Equal(gotLabels, wantLabels) {
fmt.Printf("%#v", gotLabels)
fmt.Printf("%#v", wantLabels)
t.Errorf("Expected parent goroutine's profile labels to be empty after Do, got %v", gotLabels)
package runtime_test
import (
- "reflect"
. "runtime"
+ "slices"
"testing"
"time"
"unsafe"
}
read := func(t *testing.T, b *ProfBuf, data []uint64, tags []unsafe.Pointer) {
rdata, rtags, eof := b.Read(ProfBufNonBlocking)
- if !reflect.DeepEqual(rdata, data) || !reflect.DeepEqual(rtags, tags) {
+ if !slices.Equal(rdata, data) || !slices.Equal(rtags, tags) {
t.Fatalf("unexpected profile read:\nhave data %#x\nwant data %#x\nhave tags %#x\nwant tags %#x", rdata, data, rtags, tags)
}
if eof {
go func() {
eof := data == nil
rdata, rtags, reof := b.Read(ProfBufBlocking)
- if !reflect.DeepEqual(rdata, data) || !reflect.DeepEqual(rtags, tags) || reof != eof {
+ if !slices.Equal(rdata, data) || !slices.Equal(rtags, tags) || reof != eof {
// Errorf, not Fatalf, because called in goroutine.
t.Errorf("unexpected profile read:\nhave data %#x\nwant data %#x\nhave tags %#x\nwant tags %#x\nhave eof=%v, want %v", rdata, data, rtags, tags, reof, eof)
}
import (
"fmt"
- "reflect"
"runtime"
+ "slices"
"strings"
"testing"
)
}
for i := 0; i < N; i++ {
- if !reflect.DeepEqual(out[0], out[i]) {
+ if !slices.Equal(out[0], out[i]) {
return // found a different order
}
}