mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-10 06:57:24 +00:00
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.
This commit is contained in:
39
internal/p2p/pqueue_test.go
Normal file
39
internal/p2p/pqueue_test.go
Normal 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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user