mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-10-11 00:12:40 +02:00
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:
committed by
Olaoluwa Osuntokun
parent
06946f3911
commit
22d90d6b35
43
htlcswitch/queue_test.go
Normal file
43
htlcswitch/queue_test.go
Normal file
@@ -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