Compare commits

...

5 Commits

Author SHA1 Message Date
William Banfield
a2fd106b62 change to use only one channel 2021-07-26 09:30:10 -04:00
William Banfield
537b04d59d Update internal/p2p/pqueue_test.go to remove extra line
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
2021-07-26 09:15:15 -04:00
William Banfield
a23b31d6e6 Merge branch 'master' into wb/pqueue-close-test 2021-07-26 09:14:45 -04:00
Callum Waters
a341a626e0 p2p: avoid blocking on the dequeCh (#6765) 2021-07-26 09:09:07 -04:00
William Banfield
a1a7e5888d p2p: add test for pqueue dequeue full error 2021-07-23 13:50:31 -04:00
2 changed files with 44 additions and 1 deletions

View File

@@ -257,7 +257,11 @@ func (s *pqScheduler) process() {
s.metrics.PeerSendBytesTotal.With(
"chID", chIDStr,
"peer_id", string(pqEnv.envelope.To)).Add(float64(pqEnv.size))
s.dequeueCh <- pqEnv.envelope
select {
case s.dequeueCh <- pqEnv.envelope:
case <-s.closer.Done():
return
}
}
case <-s.closer.Done():

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")
}
}