File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -201,6 +201,34 @@ func TestUpdateSyncDifferentHeads(t *testing.T) {
201201 chain .ExpNextSyncPeriod (t , 17 )
202202}
203203
204+ func TestRangeLock (t * testing.T ) {
205+ r := make (rangeLock )
206+
207+ // Lock from 0 to 99.
208+ r .lock (0 , 100 , 1 )
209+ for i := 0 ; i < 100 ; i ++ {
210+ if v , ok := r [uint64 (i )]; v <= 0 || ! ok {
211+ t .Fatalf ("integer space: %d not locked" , i )
212+ }
213+ }
214+
215+ // Unlock from 0 to 99.
216+ r .lock (0 , 100 , - 1 )
217+ for i := 0 ; i < 100 ; i ++ {
218+ if v , ok := r [uint64 (i )]; v > 0 || ok {
219+ t .Fatalf ("integer space: %d is locked" , i )
220+ }
221+ }
222+
223+ // Lock from 0 to 99 then unlock from 10 to 59.
224+ r .lock (0 , 100 , 1 )
225+ r .lock (10 , 50 , - 1 )
226+ first , count := r .firstUnlocked (0 , 100 )
227+ if first != 10 || count != 50 {
228+ t .Fatalf ("unexpected first: %d or count: %d" , first , count )
229+ }
230+ }
231+
204232func testRespUpdate (request requestWithID ) request.Response {
205233 var resp RespUpdates
206234 if request .request == nil {
You can’t perform that action at this time.
0 commit comments