matrix-pinecone/router/queuefifo_test.go
devonh 9afe5eda9b
Fix simulator ping convergence (#46)
* Sim - limit ping worker count to prevent overfilling peer queues

* Log when dropping frames due to a full queue

* Add proper logging to the queues

* Fix queue unit test
2022-05-11 16:53:03 +00:00

35 lines
845 B
Go

package router
import (
"testing"
"github.com/matrix-org/pinecone/types"
)
func TestLimitedFIFO(t *testing.T) {
q := newFIFOQueue(5, nil)
// the actual allocated queue size will be 1 more than the
// supplied, so that when we push an entry and assign the
// next channel, that won't cause a reallocation of the queue
if s := q.queuesize(); s != 6 {
t.Fatalf("expected queue size to be 6 but it was %d", s)
}
for i := 0; i < 10; i++ {
added := q.push(&types.Frame{})
switch {
case i < 5 && !added:
t.Fatalf("expected %d to be added", i)
case i >= 5 && added:
t.Fatalf("expected %d to not be added", i)
}
}
if s := q.queuecount(); s != 5 {
t.Fatalf("expected final queue count to be 5 but it was %d", s)
}
if s := q.queuesize(); s != 6 {
t.Fatalf("expected final queue size to be 6 but it was %d", s)
}
}