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.

39 lines
786 B

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