dashboard_test.go 903 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package dashboard
  2. import (
  3. "sync"
  4. "testing"
  5. "time"
  6. )
  7. func TestRunStop(t *testing.T) {
  8. config := &Config{
  9. Enabled: true,
  10. ListenInterface: ":8082",
  11. TickInterval: "5s",
  12. MaxWindow: "24h",
  13. RankingUpdateInterval: "6h",
  14. }
  15. var wg sync.WaitGroup
  16. wg.Add(1)
  17. go func() {
  18. Run(config)
  19. wg.Done()
  20. }()
  21. // give Run some time to start
  22. time.Sleep(time.Second)
  23. Stop()
  24. // Wait for Run() to exit
  25. wg.Wait()
  26. }
  27. // Test if starting with a bad interface address
  28. func TestRunStopBadAddress(t *testing.T) {
  29. config := &Config{
  30. Enabled: true,
  31. ListenInterface: "1.1.1.1:0",
  32. TickInterval: "5s",
  33. MaxWindow: "24h",
  34. RankingUpdateInterval: "6h",
  35. }
  36. var wg sync.WaitGroup
  37. wg.Add(1)
  38. go func() {
  39. Run(config)
  40. wg.Done()
  41. }()
  42. time.Sleep(time.Second * 2)
  43. Stop()
  44. // Wait for Run() to exit
  45. wg.Wait()
  46. }