diff --git a/htlcswitch/link_test.go b/htlcswitch/link_test.go index cf748cd2..693ef680 100644 --- a/htlcswitch/link_test.go +++ b/htlcswitch/link_test.go @@ -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, diff --git a/htlcswitch/mock.go b/htlcswitch/mock.go index 48d47128..3eb86821 100644 --- a/htlcswitch/mock.go +++ b/htlcswitch/mock.go @@ -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[:]) diff --git a/htlcswitch/test_utils.go b/htlcswitch/test_utils.go index e544a0f6..33ae866d 100644 --- a/htlcswitch/test_utils.go +++ b/htlcswitch/test_utils.go @@ -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 {