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.

55 lines
1.7 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, 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, 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, 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("NonExistant", func(t *testing.T) {
  39. opts := RouterOptions{QueueType: "fast"}
  40. _, err := NewRouter(log.NewNopLogger(), nil, types.NodeInfo{}, nil, nil, nil, nil, opts)
  41. require.Error(t, err)
  42. require.Contains(t, err.Error(), "fast")
  43. })
  44. t.Run("InternalsSafeWhenUnspecified", func(t *testing.T) {
  45. r := &Router{}
  46. require.Zero(t, r.options.QueueType)
  47. fn, err := r.createQueueFactory()
  48. require.Error(t, err)
  49. require.Nil(t, fn)
  50. })
  51. }