From a751eee7f25e49834f3d13044498e2e7c28fa502 Mon Sep 17 00:00:00 2001 From: William Banfield <4561443+williambanfield@users.noreply.github.com> Date: Mon, 26 Jul 2021 15:22:32 -0400 Subject: [PATCH] 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. --- internal/p2p/pqueue_test.go | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 internal/p2p/pqueue_test.go diff --git a/internal/p2p/pqueue_test.go b/internal/p2p/pqueue_test.go new file mode 100644 index 000000000..ddb7addbe --- /dev/null +++ b/internal/p2p/pqueue_test.go @@ -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") + } +}