Browse Source

[monitor] make linters happy

pull/1943/head
Anton Kaliaev 7 years ago
parent
commit
2f1c7a3646
No known key found for this signature in database GPG Key ID: 7B6881D965918214
3 changed files with 37 additions and 67 deletions
  1. +5
    -9
      tm-monitor/monitor/monitor_test.go
  2. +21
    -37
      tm-monitor/monitor/network_test.go
  3. +11
    -21
      tm-monitor/monitor/node_test.go

+ 5
- 9
tm-monitor/monitor/monitor_test.go View File

@ -15,27 +15,23 @@ import (
)
func TestMonitorUpdatesNumberOfValidators(t *testing.T) {
assert := assert.New(t)
m := startMonitor(t)
defer m.Stop()
n, _ := createValidatorNode(t)
m.Monitor(n)
assert.Equal(1, m.Network.NumNodesMonitored)
assert.Equal(1, m.Network.NumNodesMonitoredOnline)
assert.Equal(t, 1, m.Network.NumNodesMonitored)
assert.Equal(t, 1, m.Network.NumNodesMonitoredOnline)
time.Sleep(1 * time.Second)
assert.Equal(1, m.Network.NumValidators)
assert.Equal(t, 1, m.Network.NumValidators)
}
func TestMonitorRecalculatesNetworkUptime(t *testing.T) {
assert := assert.New(t)
m := startMonitor(t)
defer m.Stop()
assert.Equal(100.0, m.Network.Uptime())
assert.Equal(t, 100.0, m.Network.Uptime())
n, _ := createValidatorNode(t)
m.Monitor(n)
@ -45,7 +41,7 @@ func TestMonitorRecalculatesNetworkUptime(t *testing.T) {
m.Network.NodeIsOnline(n.Name)
time.Sleep(1 * time.Second)
assert.True(m.Network.Uptime() < 100.0, "Uptime should be less than 100%")
assert.True(t, m.Network.Uptime() < 100.0, "Uptime should be less than 100%")
}
func startMonitor(t *testing.T) *monitor.Monitor {


+ 21
- 37
tm-monitor/monitor/network_test.go View File

@ -10,86 +10,70 @@ import (
)
func TestNetworkNewBlock(t *testing.T) {
assert := assert.New(t)
n := monitor.NewNetwork()
n.NewBlock(tmtypes.Header{Height: 5, NumTxs: 100})
assert.Equal(uint64(5), n.Height)
assert.Equal(0.0, n.AvgBlockTime)
assert.Equal(0.0, n.AvgTxThroughput)
assert.Equal(t, uint64(5), n.Height)
assert.Equal(t, 0.0, n.AvgBlockTime)
assert.Equal(t, 0.0, n.AvgTxThroughput)
}
func TestNetworkNewBlockLatency(t *testing.T) {
assert := assert.New(t)
n := monitor.NewNetwork()
n.NewBlockLatency(9000000.0) // nanoseconds
assert.Equal(0.0, n.AvgBlockLatency)
assert.Equal(t, 0.0, n.AvgBlockLatency)
}
func TestNetworkNodeIsDownThenOnline(t *testing.T) {
assert := assert.New(t)
n := monitor.NewNetwork()
n.NewNode("test")
n.NodeIsDown("test")
assert.Equal(0, n.NumNodesMonitoredOnline)
assert.Equal(monitor.Dead, n.Health)
assert.Equal(t, 0, n.NumNodesMonitoredOnline)
assert.Equal(t, monitor.Dead, n.Health)
n.NodeIsDown("test")
assert.Equal(0, n.NumNodesMonitoredOnline)
assert.Equal(t, 0, n.NumNodesMonitoredOnline)
n.NodeIsOnline("test")
assert.Equal(1, n.NumNodesMonitoredOnline)
assert.Equal(monitor.ModerateHealth, n.Health)
assert.Equal(t, 1, n.NumNodesMonitoredOnline)
assert.Equal(t, monitor.ModerateHealth, n.Health)
n.NodeIsOnline("test")
assert.Equal(1, n.NumNodesMonitoredOnline)
assert.Equal(t, 1, n.NumNodesMonitoredOnline)
}
func TestNetworkNewNode(t *testing.T) {
assert := assert.New(t)
n := monitor.NewNetwork()
assert.Equal(0, n.NumNodesMonitored)
assert.Equal(0, n.NumNodesMonitoredOnline)
assert.Equal(t, 0, n.NumNodesMonitored)
assert.Equal(t, 0, n.NumNodesMonitoredOnline)
n.NewNode("test")
assert.Equal(1, n.NumNodesMonitored)
assert.Equal(1, n.NumNodesMonitoredOnline)
assert.Equal(t, 1, n.NumNodesMonitored)
assert.Equal(t, 1, n.NumNodesMonitoredOnline)
}
func TestNetworkNodeDeleted(t *testing.T) {
assert := assert.New(t)
n := monitor.NewNetwork()
n.NewNode("test")
n.NodeDeleted("test")
assert.Equal(0, n.NumNodesMonitored)
assert.Equal(0, n.NumNodesMonitoredOnline)
assert.Equal(t, 0, n.NumNodesMonitored)
assert.Equal(t, 0, n.NumNodesMonitoredOnline)
}
func TestNetworkGetHealthString(t *testing.T) {
assert := assert.New(t)
n := monitor.NewNetwork()
assert.Equal("full", n.GetHealthString())
assert.Equal(t, "full", n.GetHealthString())
n.Health = monitor.ModerateHealth
assert.Equal("moderate", n.GetHealthString())
assert.Equal(t, "moderate", n.GetHealthString())
n.Health = monitor.Dead
assert.Equal("dead", n.GetHealthString())
assert.Equal(t, "dead", n.GetHealthString())
}
func TestNetworkUptime(t *testing.T) {
assert := assert.New(t)
n := monitor.NewNetwork()
assert.Equal(100.0, n.Uptime())
assert.Equal(t, 100.0, n.Uptime())
}
func TestNetworkStartTime(t *testing.T) {
assert := assert.New(t)
n := monitor.NewNetwork()
assert.True(n.StartTime().Before(time.Now()))
assert.True(t, n.StartTime().Before(time.Now()))
}

+ 11
- 21
tm-monitor/monitor/node_test.go View File

@ -19,18 +19,14 @@ const (
)
func TestNodeStartStop(t *testing.T) {
assert := assert.New(t)
n, _ := startValidatorNode(t)
defer n.Stop()
assert.Equal(true, n.Online)
assert.Equal(true, n.IsValidator)
assert.Equal(t, true, n.Online)
assert.Equal(t, true, n.IsValidator)
}
func TestNodeNewBlockReceived(t *testing.T) {
assert := assert.New(t)
blockCh := make(chan tmtypes.Header, 100)
n, emMock := startValidatorNode(t)
defer n.Stop()
@ -39,13 +35,11 @@ func TestNodeNewBlockReceived(t *testing.T) {
blockHeader := &tmtypes.Header{Height: 5}
emMock.Call("eventCallback", &em.EventMetric{}, tmtypes.TMEventData{tmtypes.EventDataNewBlockHeader{blockHeader}})
assert.Equal(uint64(5), n.Height)
assert.Equal(*blockHeader, <-blockCh)
assert.Equal(t, uint64(5), n.Height)
assert.Equal(t, *blockHeader, <-blockCh)
}
func TestNodeNewBlockLatencyReceived(t *testing.T) {
assert := assert.New(t)
blockLatencyCh := make(chan float64, 100)
n, emMock := startValidatorNode(t)
defer n.Stop()
@ -53,13 +47,11 @@ func TestNodeNewBlockLatencyReceived(t *testing.T) {
emMock.Call("latencyCallback", 1000000.0)
assert.Equal(1.0, n.BlockLatency)
assert.Equal(1000000.0, <-blockLatencyCh)
assert.Equal(t, 1.0, n.BlockLatency)
assert.Equal(t, 1000000.0, <-blockLatencyCh)
}
func TestNodeConnectionLost(t *testing.T) {
assert := assert.New(t)
disconnectCh := make(chan bool, 100)
n, emMock := startValidatorNode(t)
defer n.Stop()
@ -67,20 +59,18 @@ func TestNodeConnectionLost(t *testing.T) {
emMock.Call("disconnectCallback")
assert.Equal(true, <-disconnectCh)
assert.Equal(false, n.Online)
assert.Equal(t, true, <-disconnectCh)
assert.Equal(t, false, n.Online)
}
func TestNumValidators(t *testing.T) {
assert := assert.New(t)
n, _ := startValidatorNode(t)
defer n.Stop()
height, num, err := n.NumValidators()
assert.Nil(err)
assert.Equal(uint64(blockHeight), height)
assert.Equal(1, num)
assert.Nil(t, err)
assert.Equal(t, uint64(blockHeight), height)
assert.Equal(t, 1, num)
}
func startValidatorNode(t *testing.T) (n *monitor.Node, emMock *mock.EventMeter) {


Loading…
Cancel
Save