From a1a7e5888d3cce1896e7fc8db2ff960e396db8f6 Mon Sep 17 00:00:00 2001 From: William Banfield Date: Fri, 23 Jul 2021 13:50:31 -0400 Subject: [PATCH] p2p: add test for pqueue dequeue full error --- internal/p2p/pqueue_test.go | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 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..20128ef0e --- /dev/null +++ b/internal/p2p/pqueue_test.go @@ -0,0 +1,45 @@ +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}, + {ID: 0x02, Priority: 1, MaxSendBytes: 4}, + {ID: 0x03, Priority: 1, MaxSendBytes: 4}, + {ID: 0x04, Priority: 1, MaxSendBytes: 4}, + {ID: 0x05, Priority: 1, MaxSendBytes: 4}, + {ID: 0x06, 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") + } + +}