chainntnfs: Implement unbounded concurrent-safe FIFO queue.
This can be used in at least one place in the notifiers to improve efficiency and reduce complexity.
This commit is contained in:
1 parent
555cead5ad
commit
726c8b2301
2 files changed
+112
No files matched your search
@@ -0,0 +1,26 @@
|
||||
package chainntnfs_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
)
|
||||
|
||||
func TestConcurrentQueue(t *testing.T) {
|
||||
queue := chainntnfs.NewConcurrentQueue(100)
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user