1
- package graph_test
1
+ package discovery
2
2
3
3
import (
4
4
"encoding/binary"
5
+ "errors"
6
+ "sync"
5
7
"testing"
6
8
"time"
7
9
8
- "github.com/lightningnetwork/lnd/graph"
9
10
"github.com/lightningnetwork/lnd/lnwire"
10
11
"github.com/stretchr/testify/require"
11
12
)
@@ -22,18 +23,38 @@ func TestValidationBarrierSemaphore(t *testing.T) {
22
23
)
23
24
24
25
quit := make (chan struct {})
25
- barrier := graph .NewValidationBarrier (numTasks , quit )
26
+ barrier := NewValidationBarrier (numTasks , quit )
27
+
28
+ var scidMtx sync.RWMutex
29
+ currentScid := lnwire.ShortChannelID {}
26
30
27
31
// Saturate the semaphore with jobs.
28
32
for i := 0 ; i < numTasks ; i ++ {
29
- barrier .InitJobDependencies (nil )
33
+ scidMtx .Lock ()
34
+ dummyUpdate := & lnwire.ChannelUpdate1 {
35
+ ShortChannelID : currentScid ,
36
+ }
37
+ currentScid .TxIndex ++
38
+ scidMtx .Unlock ()
39
+
40
+ _ , err := barrier .InitJobDependencies (dummyUpdate )
41
+ require .NoError (t , err )
30
42
}
31
43
32
44
// Spawn additional tasks that will signal completion when added.
33
45
jobAdded := make (chan struct {})
34
46
for i := 0 ; i < numPendingTasks ; i ++ {
35
47
go func () {
36
- barrier .InitJobDependencies (nil )
48
+ scidMtx .Lock ()
49
+ dummyUpdate := & lnwire.ChannelUpdate1 {
50
+ ShortChannelID : currentScid ,
51
+ }
52
+ currentScid .TxIndex ++
53
+ scidMtx .Unlock ()
54
+
55
+ _ , err := barrier .InitJobDependencies (dummyUpdate )
56
+ require .NoError (t , err )
57
+
37
58
jobAdded <- struct {}{}
38
59
}()
39
60
}
@@ -70,12 +91,12 @@ func TestValidationBarrierQuit(t *testing.T) {
70
91
)
71
92
72
93
quit := make (chan struct {})
73
- barrier := graph . NewValidationBarrier (2 * numTasks , quit )
94
+ barrier := NewValidationBarrier (2 * numTasks , quit )
74
95
75
96
// Create a set of unique channel announcements that we will prep for
76
97
// validation.
77
98
anns := make ([]* lnwire.ChannelAnnouncement1 , 0 , numTasks )
78
- parentJobIDs := make ([]graph. JobID , 0 , numTasks )
99
+ parentJobIDs := make ([]JobID , 0 , numTasks )
79
100
for i := 0 ; i < numTasks ; i ++ {
80
101
anns = append (anns , & lnwire.ChannelAnnouncement1 {
81
102
ShortChannelID : lnwire .NewShortChanIDFromInt (uint64 (i )),
@@ -91,7 +112,7 @@ func TestValidationBarrierQuit(t *testing.T) {
91
112
// Create a set of channel updates, that must wait until their
92
113
// associated channel announcement has been verified.
93
114
chanUpds := make ([]* lnwire.ChannelUpdate1 , 0 , numTasks )
94
- childJobIDs := make ([]graph. JobID , 0 , numTasks )
115
+ childJobIDs := make ([]JobID , 0 , numTasks )
95
116
for i := 0 ; i < numTasks ; i ++ {
96
117
chanUpds = append (chanUpds , & lnwire.ChannelUpdate1 {
97
118
ShortChannelID : lnwire .NewShortChanIDFromInt (uint64 (i )),
@@ -154,11 +175,12 @@ func TestValidationBarrierQuit(t *testing.T) {
154
175
t .Fatalf ("unexpected failure while waiting: %v" , err )
155
176
156
177
// Last half should return the shutdown error.
157
- case i >= numTasks / 2 && ! graph . IsError (
158
- err , graph . ErrVBarrierShuttingDown ,
178
+ case i >= numTasks / 2 && ! errors . Is (
179
+ err , ErrVBarrierShuttingDown ,
159
180
):
181
+
160
182
t .Fatalf ("expected failure after quitting: want %v, " +
161
- "got %v" , graph . ErrVBarrierShuttingDown , err )
183
+ "got %v" , ErrVBarrierShuttingDown , err )
162
184
}
163
185
}
164
186
}
@@ -175,7 +197,7 @@ func TestValidationBarrierParentJobsClear(t *testing.T) {
175
197
)
176
198
177
199
quit := make (chan struct {})
178
- barrier := graph . NewValidationBarrier (numTasks , quit )
200
+ barrier := NewValidationBarrier (numTasks , quit )
179
201
180
202
sharedScid := lnwire .NewShortChanIDFromInt (0 )
181
203
sharedNodeID := nodeIDFromInt (0 )
@@ -221,8 +243,8 @@ func TestValidationBarrierParentJobsClear(t *testing.T) {
221
243
childID2 , err := barrier .InitJobDependencies (node1 )
222
244
require .NoError (t , err )
223
245
224
- run := func (vb * graph. ValidationBarrier , childJobID graph. JobID ,
225
- job interface {}, resp chan error , start chan error ) {
246
+ run := func (vb * ValidationBarrier , childJobID JobID , job interface {} ,
247
+ resp chan error , start chan error ) {
226
248
227
249
close (start )
228
250
0 commit comments