Skip to content

Commit

Permalink
[FIXED] PS test to reduce failures in some situations
Browse files Browse the repository at this point in the history
Added garbage collection before each capture method and bump the
delta threshold to 1MB.

Resolves #310
  • Loading branch information
kozlovic committed Jul 18, 2016
1 parent b14d3b9 commit d21210e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 5 additions & 1 deletion server/pse/pse_test.go
Expand Up @@ -17,6 +17,8 @@ func TestPSEmulation(t *testing.T) {
var rss, vss, psRss, psVss int64
var pcpu, psPcpu float64

runtime.GC()

// PS version first
pidStr := fmt.Sprintf("%d", os.Getpid())
out, err := exec.Command("ps", "o", "pcpu=,rss=,vsz=", "-p", pidStr).Output()
Expand All @@ -28,6 +30,8 @@ func TestPSEmulation(t *testing.T) {
psRss *= 1024 // 1k blocks, want bytes.
psVss *= 1024 // 1k blocks, want bytes.

runtime.GC()

// Our internal version
ProcUsage(&pcpu, &rss, &vss)

Expand All @@ -45,7 +49,7 @@ func TestPSEmulation(t *testing.T) {
if delta < 0 {
delta = -delta
}
if delta > 512*1024 { // 512k
if delta > 1024*1024 { // 1MB
t.Fatalf("RSSs did not match close enough: %d vs %d", rss, psRss)
}
}
Expand Down
9 changes: 8 additions & 1 deletion server/pse/pse_windows_test.go
Expand Up @@ -6,6 +6,7 @@ package pse
import (
"fmt"
"os/exec"
"runtime"
"strconv"
"strings"
"testing"
Expand All @@ -26,7 +27,7 @@ func checkValues(t *testing.T, pcpu, tPcpu float64, rss, tRss int64) {
if delta < 0 {
delta = -delta
}
if delta > 200*1024 { // 200k - basically sanity check
if delta > 1024*1024 { // 1MB
t.Fatalf("RSSs did not match close enough: %d vs %d", rss, tRss)
}
}
Expand All @@ -36,10 +37,14 @@ func TestPSEmulationWin(t *testing.T) {
var pcpu, tPcpu float64
var rss, vss, tRss int64

runtime.GC()

if err := ProcUsage(&pcpu, &rss, &vss); err != nil {
t.Fatalf("Error: %v", err)
}

runtime.GC()

imageName := getProcessImageName()
// query the counters using typeperf
out, err := exec.Command("typeperf.exe",
Expand Down Expand Up @@ -70,6 +75,8 @@ func TestPSEmulationWin(t *testing.T) {

checkValues(t, pcpu, tPcpu, rss, tRss)

runtime.GC()

// Again to test caching
if err = ProcUsage(&pcpu, &rss, &vss); err != nil {
t.Fatalf("Error: %v", err)
Expand Down

0 comments on commit d21210e

Please sign in to comment.