Browse Source

p2p: add test for pqueue dequeue full error (#6760)

This adds a test for closing the `pqueue` while the `pqueue` contains data that has not yet been dequeued.

This issue was found while debugging #6705 

This test will fail until @cmwaters fix for this condition is merged.
pull/6771/head
William Banfield 3 years ago
committed by GitHub
parent
commit
a751eee7f2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 39 additions and 0 deletions
  1. +39
    -0
      internal/p2p/pqueue_test.go

+ 39
- 0
internal/p2p/pqueue_test.go View File

@ -0,0 +1,39 @@
package p2p
import (
"testing"
"time"
"github.com/tendermint/tendermint/libs/log"
)
func TestCloseWhileDequeueFull(t *testing.T) {
enqueueLength := 5
chDescs := []ChannelDescriptor{
{ID: 0x01, Priority: 1, MaxSendBytes: 4},
}
pqueue := newPQScheduler(log.NewNopLogger(), NopMetrics(), chDescs, uint(enqueueLength), 1, 120)
for i := 0; i < enqueueLength; i++ {
pqueue.enqueue() <- Envelope{
channelID: 0x01,
Message: &testMessage{Value: "foo"}, // 5 bytes
}
}
go pqueue.process()
// sleep to allow context switch for process() to run
time.Sleep(10 * time.Millisecond)
doneCh := make(chan struct{})
go func() {
pqueue.close()
close(doneCh)
}()
select {
case <-doneCh:
case <-time.After(2 * time.Second):
t.Fatal("pqueue failed to close")
}
}

Loading…
Cancel
Save