open-nomad/client/stats/host_test.go
James Nugent 448145872f client: Guard against "NaN" values from floats
This commit protects against finding `0.NaN` tokens in JSON streams
because of infinity representation on serialization.
2017-09-08 16:21:07 -05:00

33 lines
639 B
Go

package stats
import (
"testing"
"github.com/shirou/gopsutil/cpu"
)
func TestHostCpuStatsCalculator_Nan(t *testing.T) {
times := cpu.TimesStat{
User: 0.0,
Idle: 100.0,
System: 0.0,
}
calculator := NewHostCpuStatsCalculator()
calculator.Calculate(times)
idle, user, system, total := calculator.Calculate(times)
if idle != 100.0 {
t.Errorf("idle: Expected: %f, Got %f", 100.0, idle)
}
if user != 0.0 {
t.Errorf("user: Expected: %f, Got %f", 0.0, user)
}
if system != 0.0 {
t.Errorf("system: Expected: %f, Got %f", 0.0, system)
}
if total != 0.0 {
t.Errorf("total: Expected: %f, Got %f", 0.0, total)
}
}