You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

39 lines
786 B

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