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.

80 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.Header{Height: 5, NumTxs: 100})
  12. assert.Equal(t, int64(5), n.Height)
  13. assert.Equal(t, 0.0, n.AvgBlockTime)
  14. assert.Equal(t, 0.0, n.AvgTxThroughput)
  15. }
  16. func TestNetworkNewBlockLatency(t *testing.T) {
  17. n := monitor.NewNetwork()
  18. n.NewBlockLatency(9000000.0) // nanoseconds
  19. assert.Equal(t, 0.0, n.AvgBlockLatency)
  20. }
  21. func TestNetworkNodeIsDownThenOnline(t *testing.T) {
  22. n := monitor.NewNetwork()
  23. n.NewNode("test")
  24. n.NodeIsDown("test")
  25. assert.Equal(t, 0, n.NumNodesMonitoredOnline)
  26. assert.Equal(t, monitor.Dead, n.Health)
  27. n.NodeIsDown("test")
  28. assert.Equal(t, 0, n.NumNodesMonitoredOnline)
  29. n.NodeIsOnline("test")
  30. assert.Equal(t, 1, n.NumNodesMonitoredOnline)
  31. assert.Equal(t, monitor.ModerateHealth, n.Health)
  32. n.NodeIsOnline("test")
  33. assert.Equal(t, 1, n.NumNodesMonitoredOnline)
  34. }
  35. func TestNetworkNewNode(t *testing.T) {
  36. n := monitor.NewNetwork()
  37. assert.Equal(t, 0, n.NumNodesMonitored)
  38. assert.Equal(t, 0, n.NumNodesMonitoredOnline)
  39. n.NewNode("test")
  40. assert.Equal(t, 1, n.NumNodesMonitored)
  41. assert.Equal(t, 1, n.NumNodesMonitoredOnline)
  42. }
  43. func TestNetworkNodeDeleted(t *testing.T) {
  44. n := monitor.NewNetwork()
  45. n.NewNode("test")
  46. n.NodeDeleted("test")
  47. assert.Equal(t, 0, n.NumNodesMonitored)
  48. assert.Equal(t, 0, n.NumNodesMonitoredOnline)
  49. }
  50. func TestNetworkGetHealthString(t *testing.T) {
  51. n := monitor.NewNetwork()
  52. assert.Equal(t, "full", n.GetHealthString())
  53. n.Health = monitor.ModerateHealth
  54. assert.Equal(t, "moderate", n.GetHealthString())
  55. n.Health = monitor.Dead
  56. assert.Equal(t, "dead", n.GetHealthString())
  57. }
  58. func TestNetworkUptime(t *testing.T) {
  59. n := monitor.NewNetwork()
  60. assert.Equal(t, 100.0, n.Uptime())
  61. }
  62. func TestNetworkStartTime(t *testing.T) {
  63. n := monitor.NewNetwork()
  64. assert.True(t, n.StartTime().Before(time.Now()))
  65. }