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.

42 lines
856 B

  1. package p2p
  2. import (
  3. "testing"
  4. "time"
  5. gogotypes "github.com/gogo/protobuf/types"
  6. "github.com/tendermint/tendermint/libs/log"
  7. )
  8. type testMessage = gogotypes.StringValue
  9. func TestCloseWhileDequeueFull(t *testing.T) {
  10. enqueueLength := 5
  11. chDescs := []*ChannelDescriptor{
  12. {ID: 0x01, Priority: 1},
  13. }
  14. pqueue := newPQScheduler(log.NewNopLogger(), NopMetrics(), chDescs, uint(enqueueLength), 1, 120)
  15. for i := 0; i < enqueueLength; i++ {
  16. pqueue.enqueue() <- Envelope{
  17. channelID: 0x01,
  18. Message: &testMessage{Value: "foo"}, // 5 bytes
  19. }
  20. }
  21. go pqueue.process()
  22. // sleep to allow context switch for process() to run
  23. time.Sleep(10 * time.Millisecond)
  24. doneCh := make(chan struct{})
  25. go func() {
  26. pqueue.close()
  27. close(doneCh)
  28. }()
  29. select {
  30. case <-doneCh:
  31. case <-time.After(2 * time.Second):
  32. t.Fatal("pqueue failed to close")
  33. }
  34. }