2018-10-12 18:08:14 +03:00
|
|
|
package queue_test
|
2017-09-29 22:09:37 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-10-12 18:08:14 +03:00
|
|
|
"github.com/lightningnetwork/lnd/queue"
|
2017-09-29 22:09:37 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestConcurrentQueue(t *testing.T) {
|
2018-10-12 18:08:14 +03:00
|
|
|
queue := queue.NewConcurrentQueue(100)
|
2017-09-29 22:09:37 +03:00
|
|
|
queue.Start()
|
|
|
|
defer queue.Stop()
|
|
|
|
|
|
|
|
// Pushes should never block for long.
|
|
|
|
for i := 0; i < 1000; i++ {
|
|
|
|
queue.ChanIn() <- i
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pops also should not block for long. Expect elements in FIFO order.
|
|
|
|
for i := 0; i < 1000; i++ {
|
|
|
|
item := <-queue.ChanOut()
|
|
|
|
if i != item.(int) {
|
|
|
|
t.Fatalf("Dequeued wrong value: expected %d, got %d", i, item.(int))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|