1
0
mirror of https://github.com/moby/moby.git synced 2025-04-18 20:44:11 +03:00
moby/daemon/stats_unix_test.go
Patrik Leifert e22d04e8a9 Improve CPU usage parsing and error reporting
This fix address issues where the scanner was unable to properly parse longer outputs from /proc/stat. This could happen on an ARM machine with large amount of CPU cores (and interrupts). By switching to reader we have more control over data parsing and dump unnecessary data

Signed-off-by: Patrik Leifert <patrikleifert@hotmail.com>
2025-04-07 16:19:02 +02:00

31 lines
617 B
Go

//go:build !windows
package daemon
import (
"os"
"path/filepath"
"testing"
"gotest.tools/v3/assert"
)
func TestGetSystemCPUUsageParsing(t *testing.T) {
dummyFilePath := filepath.Join("testdata", "stat")
expectedCpuUsage := uint64(65647090000000)
expectedCpuNum := uint32(128)
origStatPath := procStatPath
procStatPath = dummyFilePath
defer func() { procStatPath = origStatPath }()
_, err := os.Stat(dummyFilePath)
assert.NilError(t, err)
cpuUsage, cpuNum, err := getSystemCPUUsage()
assert.Equal(t, cpuUsage, expectedCpuUsage)
assert.Equal(t, cpuNum, expectedCpuNum)
assert.NilError(t, err)
}