Skip to content

Commit

Permalink
chore(inputs.disk): Update diskio unit test (influxdata#15950)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangxianfu committed Sep 30, 2024
1 parent 778788a commit 6bc4317
Showing 1 changed file with 56 additions and 12 deletions.
68 changes: 56 additions & 12 deletions plugins/inputs/diskio/diskio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,64 @@ func TestDiskIO(t *testing.T) {
}

func TestDiskIO_util(t *testing.T) {
ps := system.NewSystemPS()
diskio := &DiskIO{
Log: testutil.Logger{},
ps: ps,
cts := map[string]disk.IOCountersStat{
"sda": {
ReadCount: 888,
WriteCount: 5341,
ReadBytes: 100000,
WriteBytes: 200000,
ReadTime: 7123,
WriteTime: 9087,
MergedReadCount: 11,
MergedWriteCount: 12,
Name: "sda",
IoTime: 123552,
SerialNumber: "ab-123-ad",
},
}

cts2 := map[string]disk.IOCountersStat{
"sda": {
ReadCount: 1000,
WriteCount: 6000,
ReadBytes: 200000,
WriteBytes: 300000,
ReadTime: 8123,
WriteTime: 9187,
MergedReadCount: 16,
MergedWriteCount: 30,
Name: "sda",
IoTime: 163552,
SerialNumber: "ab-123-ad",
},
}

var acc testutil.Accumulator
require.NoError(t, diskio.Init())
for i := 0; i < 3; i++ {
err := diskio.Gather(&acc)
require.NoError(t, err)
for _, metric := range acc.Metrics {
diskio.Log.Info(metric)
}
time.Sleep(3 * time.Second)
var mps system.MockPS
mps.On("DiskIO").Return(cts, nil)
diskio := &DiskIO{
Log: testutil.Logger{},
Devices: []string{"sd*"},
ps: &mps,
}
require.NoError(t, diskio.Init())
// gather
err := diskio.Gather(&acc)
require.Equal(t, nil, err)
// sleep
time.Sleep(10 * time.Second)
// gather twice
mps2 := system.MockPS{}
mps2.On("DiskIO").Return(cts2, nil)
diskio.ps = &mps2

err = diskio.Gather(&acc)
require.NoError(t, err)
require.True(t, acc.HasField("diskio", "io_util"), "miss io util")
require.True(t, acc.HasField("diskio", "io_svctm"), "miss io_svctm")
require.True(t, acc.HasField("diskio", "io_await"), "miss io_await")

require.True(t, acc.HasFloatField("diskio", "io_util"), "io_util not have value")
require.True(t, acc.HasFloatField("diskio", "io_svctm"), "io_svctm not have value")
require.True(t, acc.HasFloatField("diskio", "io_await"), "io_await not have value")
}

0 comments on commit 6bc4317

Please sign in to comment.