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.

62 lines
1.9 KiB

  1. package p2p
  2. import (
  3. "os"
  4. "testing"
  5. "github.com/stretchr/testify/require"
  6. "github.com/tendermint/tendermint/libs/log"
  7. )
  8. func TestRouter_ConstructQueueFactory(t *testing.T) {
  9. t.Run("ValidateOptionsPopulatesDefaultQueue", func(t *testing.T) {
  10. opts := RouterOptions{}
  11. require.NoError(t, opts.Validate())
  12. require.Equal(t, "fifo", opts.QueueType)
  13. })
  14. t.Run("Default", func(t *testing.T) {
  15. require.Zero(t, os.Getenv("TM_P2P_QUEUE"))
  16. opts := RouterOptions{}
  17. r, err := NewRouter(log.NewNopLogger(), nil, NodeInfo{}, nil, nil, nil, opts)
  18. require.NoError(t, err)
  19. _, ok := r.queueFactory(1).(*fifoQueue)
  20. require.True(t, ok)
  21. })
  22. t.Run("Fifo", func(t *testing.T) {
  23. opts := RouterOptions{QueueType: queueTypeFifo}
  24. r, err := NewRouter(log.NewNopLogger(), nil, NodeInfo{}, nil, nil, nil, opts)
  25. require.NoError(t, err)
  26. _, ok := r.queueFactory(1).(*fifoQueue)
  27. require.True(t, ok)
  28. })
  29. t.Run("Priority", func(t *testing.T) {
  30. opts := RouterOptions{QueueType: queueTypePriority}
  31. r, err := NewRouter(log.NewNopLogger(), nil, NodeInfo{}, nil, nil, nil, opts)
  32. require.NoError(t, err)
  33. q, ok := r.queueFactory(1).(*pqScheduler)
  34. require.True(t, ok)
  35. defer q.close()
  36. })
  37. t.Run("WDRR", func(t *testing.T) {
  38. opts := RouterOptions{QueueType: queueTypeWDRR}
  39. r, err := NewRouter(log.NewNopLogger(), nil, NodeInfo{}, nil, nil, nil, opts)
  40. require.NoError(t, err)
  41. q, ok := r.queueFactory(1).(*wdrrScheduler)
  42. require.True(t, ok)
  43. defer q.close()
  44. })
  45. t.Run("NonExistant", func(t *testing.T) {
  46. opts := RouterOptions{QueueType: "fast"}
  47. _, err := NewRouter(log.NewNopLogger(), nil, NodeInfo{}, nil, nil, nil, opts)
  48. require.Error(t, err)
  49. require.Contains(t, err.Error(), "fast")
  50. })
  51. t.Run("InternalsSafeWhenUnspecified", func(t *testing.T) {
  52. r := &Router{}
  53. require.Zero(t, r.options.QueueType)
  54. fn, err := r.createQueueFactory()
  55. require.Error(t, err)
  56. require.Nil(t, fn)
  57. })
  58. }