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.

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