|
|
@ -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())) |
|
|
|
} |