github.com/jrxfive/nomad@v0.6.1-0.20170802162750-1fef470e89bf/client/stats/cpu_test.go (about)

     1  package stats
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  )
     7  
     8  func TestCpuStatsPercent(t *testing.T) {
     9  	cs := NewCpuStats()
    10  	cs.Percent(79.7)
    11  	time.Sleep(1 * time.Second)
    12  	percent := cs.Percent(80.69)
    13  	expectedPercent := 98.00
    14  	if percent < expectedPercent && percent > (expectedPercent+1.00) {
    15  		t.Fatalf("expected: %v, actual: %v", expectedPercent, percent)
    16  	}
    17  }