htlcswitch: add new concurrentTester wrapper struct

In this commit we add a new wrapper struct for the testing.T struct
that allows multiple clients to attempt to fail a given test at the
same time.
This commit is contained in:
Olaoluwa Osuntokun 2017-11-11 15:05:09 -08:00
parent 861412529d
commit a702aace9c
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
3 changed files with 26 additions and 4 deletions

@ -27,6 +27,27 @@ const (
testStartingHeight = 100
)
// concurrentTester is a thread-safe wrapper around the Fatalf method of a
// *testing.T instance. With this wrapper multiple goroutines can safely
// attempt to fail a test concurrently.
type concurrentTester struct {
mtx sync.Mutex
*testing.T
}
func newConcurrentTester(t *testing.T) *concurrentTester {
return &concurrentTester{
T: t,
}
}
func (c *concurrentTester) Fatalf(format string, args ...interface{}) {
c.mtx.Lock()
defer c.mtx.Unlock()
c.T.Fatalf(format, args)
}
// messageToString is used to produce less spammy log messages in trace mode by
// setting the 'Curve" parameter to nil. Doing this avoids printing out each of
// the field elements in the curve parameters for secp256k1.
@ -1872,6 +1893,8 @@ func TestChannelRetransmission(t *testing.T) {
// Add interceptor to check the order of Bob and Alice messages.
n := newThreeHopNetwork(t,
ct := newConcurrentTester(t)
channels.aliceToBob, channels.bobToAlice,
channels.bobToCarol, channels.carolToBob,
testStartingHeight,

@ -30,7 +30,7 @@ type mockServer struct {
wg sync.WaitGroup
quit chan struct{}
t *testing.T
t testing.TB
name string
messages chan lnwire.Message
@ -46,7 +46,7 @@ type mockServer struct {
var _ Peer = (*mockServer)(nil)
func newMockServer(t *testing.T, name string) *mockServer {
func newMockServer(t testing.TB, name string) *mockServer {
var id [33]byte
h := sha256.Sum256([]byte(name))
copy(id[:], h[:])

@ -608,7 +608,6 @@ func (n *threeHopNetwork) stop() {
}
}
// clusterChannels...
type clusterChannels struct {
aliceToBob *lnwallet.LightningChannel
bobToAlice *lnwallet.LightningChannel
@ -685,7 +684,7 @@ func createClusterChannels(aliceToBob, bobToCarol btcutil.Amount) (
// alice first bob second bob carol
// channel link channel link channel link channel link
//
func newThreeHopNetwork(t *testing.T, aliceChannel, firstBobChannel,
func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
secondBobChannel, carolChannel *lnwallet.LightningChannel,
startingHeight uint32) *threeHopNetwork {