github.com/hernad/nomad@v1.6.112/helper/stats/cpu_test.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package stats
     5  
     6  import (
     7  	"testing"
     8  	"time"
     9  
    10  	"github.com/hernad/nomad/ci"
    11  )
    12  
    13  func TestCpuStatsPercent(t *testing.T) {
    14  	ci.Parallel(t)
    15  
    16  	cs := NewCpuStats()
    17  	cs.Percent(79.7)
    18  	time.Sleep(1 * time.Second)
    19  	percent := cs.Percent(80.69)
    20  	expectedPercent := 98.00
    21  	if percent < expectedPercent && percent > (expectedPercent+1.00) {
    22  		t.Fatalf("expected: %v, actual: %v", expectedPercent, percent)
    23  	}
    24  }