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.

95 lines
2.2 KiB

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