autopilot: fix chanID collision test flake by instead using atomic counter

This commit fixes a prior occasional test flake caused by the collision
of the randomly selected 64-bit integers. In order to get around this,
we now instead have a atomic monotonically increasing counter for each
channel ID used within the tests.
This commit is contained in:
Olaoluwa Osuntokun 2017-08-15 17:56:19 -07:00
parent 572eef2840
commit 8034780ca4
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -3,8 +3,8 @@ package autopilot
import ( import (
"bytes" "bytes"
"math/big" "math/big"
prand "math/rand"
"net" "net"
"sync/atomic"
"time" "time"
"github.com/boltdb/bolt" "github.com/boltdb/bolt"
@ -21,6 +21,8 @@ var (
} }
_, _ = testSig.R.SetString("63724406601629180062774974542967536251589935445068131219452686511677818569431", 10) _, _ = testSig.R.SetString("63724406601629180062774974542967536251589935445068131219452686511677818569431", 10)
_, _ = testSig.S.SetString("18801056069249825825291287104931333862866033135609736119018462340006816851118", 10) _, _ = testSig.S.SetString("18801056069249825825291287104931333862866033135609736119018462340006816851118", 10)
chanIdCounter uint64 = 0
) )
// databaseChannelGraph wraps a channeldb.ChannelGraph instance with the // databaseChannelGraph wraps a channeldb.ChannelGraph instance with the
@ -297,7 +299,8 @@ func (m memChannelGraph) ForEachNode(cb func(Node) error) error {
// randChanID generates a new random channel ID. // randChanID generates a new random channel ID.
func randChanID() lnwire.ShortChannelID { func randChanID() lnwire.ShortChannelID {
return lnwire.NewShortChanIDFromInt(uint64(prand.Int63())) id := atomic.AddUint64(&chanIdCounter, 1)
return lnwire.NewShortChanIDFromInt(id)
} }
// randKey returns a random public key. // randKey returns a random public key.