funding: fix race conditions in tests by guarding r.lastUpdated w/ a mtx

This commit is contained in:
Olaoluwa Osuntokun 2018-03-13 18:12:33 -07:00
parent 0fb7804e4a
commit 90ecc380ce
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
1 changed files with 10 additions and 0 deletions

View File

@ -70,6 +70,7 @@ type reservationWithCtx struct {
chanAmt btcutil.Amount
updateMtx sync.RWMutex
lastUpdated time.Time
updates chan *lnrpc.OpenStatusUpdate
@ -78,6 +79,9 @@ type reservationWithCtx struct {
// isLocked checks the reservation's timestamp to determine whether it is locked.
func (r *reservationWithCtx) isLocked() bool {
r.updateMtx.RLock()
defer r.updateMtx.RUnlock()
// The time zero value represents a locked reservation.
return r.lastUpdated.IsZero()
}
@ -85,11 +89,17 @@ func (r *reservationWithCtx) isLocked() bool {
// lock locks the reservation from zombie pruning by setting its timestamp to the
// zero value.
func (r *reservationWithCtx) lock() {
r.updateMtx.Lock()
defer r.updateMtx.Unlock()
r.lastUpdated = time.Time{}
}
// updateTimestamp updates the reservation's timestamp with the current time.
func (r *reservationWithCtx) updateTimestamp() {
r.updateMtx.Lock()
defer r.updateMtx.Unlock()
r.lastUpdated = time.Now()
}