File: io_test.go

package info (click to toggle)
docker.io 27.5.1%2Bdfsg4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 67,384 kB
  • sloc: sh: 5,847; makefile: 1,146; ansic: 664; python: 162; asm: 133
file content (54 lines) | stat: -rw-r--r-- 1,566 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package resources

import (
	"os"
	"path/filepath"
	"testing"

	resourcestypes "github.com/moby/buildkit/executor/resources/types"
	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestParseIOStat(t *testing.T) {
	testDir := t.TempDir()

	ioStatContents := `8:0 rbytes=1024 wbytes=2048 dbytes=4096 rios=16 wios=32 dios=64
8:1 rbytes=512 wbytes=1024 dbytes=2048 rios=8 wios=16 dios=32`
	err := os.WriteFile(filepath.Join(testDir, "io.stat"), []byte(ioStatContents), 0644)
	require.NoError(t, err)

	ioPressureContents := `some avg10=1.23 avg60=4.56 avg300=7.89 total=3031
full avg10=0.12 avg60=0.34 avg300=0.56 total=9876`
	err = os.WriteFile(filepath.Join(testDir, "io.pressure"), []byte(ioPressureContents), 0644)
	require.NoError(t, err)

	ioStat, err := getCgroupIOStat(testDir)
	require.NoError(t, err)

	var expectedPressure = &resourcestypes.Pressure{
		Some: &resourcestypes.PressureValues{
			Avg10:  float64Ptr(1.23),
			Avg60:  float64Ptr(4.56),
			Avg300: float64Ptr(7.89),
			Total:  uint64Ptr(3031),
		},
		Full: &resourcestypes.PressureValues{
			Avg10:  float64Ptr(0.12),
			Avg60:  float64Ptr(0.34),
			Avg300: float64Ptr(0.56),
			Total:  uint64Ptr(9876),
		},
	}

	expectedIOStat := &resourcestypes.IOStat{
		ReadBytes:    uint64Ptr(1024 + 512),
		WriteBytes:   uint64Ptr(2048 + 1024),
		DiscardBytes: uint64Ptr(4096 + 2048),
		ReadIOs:      uint64Ptr(16 + 8),
		WriteIOs:     uint64Ptr(32 + 16),
		DiscardIOs:   uint64Ptr(64 + 32),
		Pressure:     expectedPressure,
	}
	assert.Equal(t, expectedIOStat, ioStat)
}