You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.0 KiB

  1. package monitor_test
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/stretchr/testify/assert"
  6. monitor "github.com/tendermint/tendermint/tools/tm-monitor/monitor"
  7. tmtypes "github.com/tendermint/tendermint/types"
  8. )
  9. func TestNetworkNewBlock(t *testing.T) {
  10. n := monitor.NewNetwork()
  11. n.NewBlock(&tmtypes.Block{
  12. Header: tmtypes.Header{Height: 5},
  13. })
  14. assert.Equal(t, int64(5), n.Height)
  15. assert.Equal(t, 0.0, n.AvgBlockTime)
  16. assert.Equal(t, 0.0, n.AvgTxThroughput)
  17. }
  18. func TestNetworkNewBlockLatency(t *testing.T) {
  19. n := monitor.NewNetwork()
  20. n.NewBlockLatency(9000000.0) // nanoseconds
  21. assert.Equal(t, 0.0, n.AvgBlockLatency)
  22. }
  23. func TestNetworkNodeIsDownThenOnline(t *testing.T) {
  24. n := monitor.NewNetwork()
  25. n.NewNode("test")
  26. n.NodeIsDown("test")
  27. assert.Equal(t, 0, n.NumNodesMonitoredOnline)
  28. assert.Equal(t, monitor.Dead, n.Health)
  29. n.NodeIsDown("test")
  30. assert.Equal(t, 0, n.NumNodesMonitoredOnline)
  31. n.NodeIsOnline("test")
  32. assert.Equal(t, 1, n.NumNodesMonitoredOnline)
  33. assert.Equal(t, monitor.ModerateHealth, n.Health)
  34. n.NodeIsOnline("test")
  35. assert.Equal(t, 1, n.NumNodesMonitoredOnline)
  36. }
  37. func TestNetworkNewNode(t *testing.T) {
  38. n := monitor.NewNetwork()
  39. assert.Equal(t, 0, n.NumNodesMonitored)
  40. assert.Equal(t, 0, n.NumNodesMonitoredOnline)
  41. n.NewNode("test")
  42. assert.Equal(t, 1, n.NumNodesMonitored)
  43. assert.Equal(t, 1, n.NumNodesMonitoredOnline)
  44. }
  45. func TestNetworkNodeDeleted(t *testing.T) {
  46. n := monitor.NewNetwork()
  47. n.NewNode("test")
  48. n.NodeDeleted("test")
  49. assert.Equal(t, 0, n.NumNodesMonitored)
  50. assert.Equal(t, 0, n.NumNodesMonitoredOnline)
  51. }
  52. func TestNetworkGetHealthString(t *testing.T) {
  53. n := monitor.NewNetwork()
  54. assert.Equal(t, "full", n.GetHealthString())
  55. n.Health = monitor.ModerateHealth
  56. assert.Equal(t, "moderate", n.GetHealthString())
  57. n.Health = monitor.Dead
  58. assert.Equal(t, "dead", n.GetHealthString())
  59. }
  60. func TestNetworkUptime(t *testing.T) {
  61. n := monitor.NewNetwork()
  62. assert.Equal(t, 100.0, n.Uptime())
  63. }
  64. func TestNetworkStartTime(t *testing.T) {
  65. n := monitor.NewNetwork()
  66. assert.True(t, n.StartTime().Before(time.Now()))
  67. }