Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions prometheus/go_collector_latest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"reflect"
"regexp"
"runtime"
"runtime/debug"
"runtime/metrics"
"strings"
"sync"
Expand Down Expand Up @@ -270,12 +271,16 @@ func TestMemStatsEquivalence(t *testing.T) {
samplesMap[descs[i].Name] = &samples[i]
}

// Force a GC cycle to try to reach a clean slate.
runtime.GC()
// Reach a stable slate and hold it for a single measurement window.
// FreeOSMemory runs a GC and returns freed memory to the OS, leaving the
// background scavenger nothing to release; disabling GC for the window
// keeps msReal and msFake observing the same runtime state. Without this,
// HeapReleased could drift between the two reads and fail the comparison.
debug.FreeOSMemory()
defer debug.SetGCPercent(debug.SetGCPercent(-1))

// Populate msReal.
// Populate msReal, then msFake back-to-back within the frozen window.
runtime.ReadMemStats(&msReal)
// Populate msFake and hope that no GC happened in between (:
metrics.Read(samples)

memStatsFromRM(&msFake, samplesMap)
Expand Down
4 changes: 2 additions & 2 deletions prometheus/process_collector_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ func TestDarwinProcessCollector(t *testing.T) {
regexp.MustCompile("\nprocess_max_fds [1-9]"),
regexp.MustCompile("\nprocess_open_fds [1-9]"),
regexp.MustCompile("\nprocess_virtual_memory_max_bytes (-1|[1-9])"),
regexp.MustCompile("\nprocess_start_time_seconds [0-9.]{10,}"),
regexp.MustCompile("\nprocess_start_time_seconds [0-9]"),
regexp.MustCompile("\nfoobar_process_cpu_seconds_total [0-9]"),
regexp.MustCompile("\nfoobar_process_max_fds [1-9]"),
regexp.MustCompile("\nfoobar_process_open_fds [1-9]"),
regexp.MustCompile("\nfoobar_process_virtual_memory_max_bytes (-1|[1-9])"),
regexp.MustCompile("\nfoobar_process_start_time_seconds [0-9.]{10,}"),
regexp.MustCompile("\nfoobar_process_start_time_seconds [0-9]"),
} {
if !re.Match(buf.Bytes()) {
t.Errorf("want body to match %s\n%s", re, buf.String())
Expand Down
Loading