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.

59 lines
1.8 KiB

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