Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
lonord committed Jun 19, 2018
1 parent 8c9f4fb commit 7f575fe
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion netutil/netspeed.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (n *NetSpeedReader) Read() ([]NetSpeed, error) {
return nil, err
}
sMap := convertToDevStatusMapWithFilter(s, n.targetDevs)
speedList := cal(sMap, ls, int((t.UnixNano()-lt.UnixNano())/1000))
speedList := cal(sMap, ls, int((t.UnixNano()-lt.UnixNano())/1000000))
n.recordTime = t
n.statusMap = sMap
return speedList, nil
Expand Down
45 changes: 45 additions & 0 deletions netutil/netspeed_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package netutil

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestCal(t *testing.T) {
s1, err := ReadDevStatus(func(p string) (string, error) {
return data1, nil
})
assert.NoError(t, err)
s2, err := ReadDevStatus(func(p string) (string, error) {
return data2, nil
})
assert.NoError(t, err)
map1 := convertToDevStatusMap(s1)
map2 := convertToDevStatusMap(s2)
speeds := cal(map1, map2, 1000)
assert.Equal(t, len(speeds), 3)
var speed NetSpeed
for _, ss := range speeds {
if ss.DevName == "br-lan" {
speed = ss
}
}
assert.Equal(t, speed.DevName, "br-lan")
assert.Equal(t, speed.ReceiveSpeed, uint64(1000))
assert.Equal(t, speed.TransmitSpeed, uint64(2000))
}

const data1 = `Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
br-lan: 88232992879 78760799 0 0 0 0 0 0 99798877563 67202989 0 0 0 0 0 0
wlan0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
lo: 2312260588 3252792 0 0 0 0 0 0 2312260588 3252792 0 0 0 0 0 0
`

const data2 = `Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
br-lan: 88232993879 78760799 0 0 0 0 0 0 99798879563 67202989 0 0 0 0 0 0
wlan0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
lo: 2312260588 3252792 0 0 0 0 0 0 2312260588 3252792 0 0 0 0 0 0
`

0 comments on commit 7f575fe

Please sign in to comment.