htlcswitch: add packet queue
In this commit pending packet queue have been added. This queue consumes the htlc packet, store it inside the golang list and send it to the pending channel upon release notification.
This commit is contained in:
1 parent
06946f3911
commit
22d90d6b35
2 files changed
+160
No files matched your search
@@ -0,0 +1,43 @@
|
||||
package htlcswitch
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/roasbeef/btcutil"
|
||||
)
|
||||
|
||||
// TestWaitingQueueThreadSafety test the thread safety properties of the
|
||||
// waiting queue, by executing methods in seprate goroutines which operates
|
||||
// with the same data.
|
||||
func TestWaitingQueueThreadSafety(t *testing.T) {
|
||||
q := newWaitingQueue()
|
||||
|
||||
a := make([]btcutil.Amount, 1000)
|
||||
for i := 0; i < len(a); i++ {
|
||||
a[i] = btcutil.Amount(i)
|
||||
q.consume(&htlcPacket{
|
||||
amount: btcutil.Amount(i),
|
||||
htlc: &lnwire.UpdateAddHTLC{},
|
||||
})
|
||||
}
|
||||
|
||||
var b []btcutil.Amount
|
||||
for i := 0; i < len(a); i++ {
|
||||
q.release()
|
||||
|
||||
select {
|
||||
case packet := <-q.pending:
|
||||
b = append(b, packet.amount)
|
||||
|
||||
case <-time.After(2 * time.Second):
|
||||
t.Fatal("timeout")
|
||||
}
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(b, a) {
|
||||
t.Fatal("wrong order of the objects")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user