From a8a86b290ca4906ffb0da33dc2c779e285e7ff57 Mon Sep 17 00:00:00 2001 From: Carla Kirk-Cohen Date: Tue, 14 Nov 2023 15:33:52 -0500 Subject: [PATCH] peer/test: setup clean peer for each TestHandleNewPendingChannel case Running test cases in parallel with shared state means that they can intermingle if they're run at the same time and set up incorrect values when we assert on the number of channels we have. Moving the peer setup into the parallel test run fixes this because no single test case can interfere with the other. --- peer/brontide_test.go | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/peer/brontide_test.go b/peer/brontide_test.go index 10ef1bded..37803ecbc 100644 --- a/peer/brontide_test.go +++ b/peer/brontide_test.go @@ -1183,18 +1183,6 @@ func TestHandleNewPendingChannel(t *testing.T) { chanIDNotExist := lnwire.ChannelID{1} chanIDPending := lnwire.ChannelID{2} - // Create a test brontide. - dummyConfig := Config{} - peer := NewBrontide(dummyConfig) - - // Create the test state. - peer.activeChannels.Store(chanIDActive, &lnwallet.LightningChannel{}) - peer.activeChannels.Store(chanIDPending, nil) - - // Assert test state, we should have two channels store, one active and - // one pending. - require.Equal(t, 2, peer.activeChannels.Len()) - testCases := []struct { name string chanID lnwire.ChannelID @@ -1234,9 +1222,22 @@ func TestHandleNewPendingChannel(t *testing.T) { t.Parallel() require := require.New(t) - // Get the number of channels before mutating the - // state. - numChans := peer.activeChannels.Len() + // Create a test brontide. + dummyConfig := Config{} + peer := NewBrontide(dummyConfig) + + // Create the test state. + peer.activeChannels.Store( + chanIDActive, &lnwallet.LightningChannel{}, + ) + peer.activeChannels.Store(chanIDPending, nil) + + // Assert test state, we should have two channels + // store, one active and one pending. + numChans := 2 + require.EqualValues( + numChans, peer.activeChannels.Len(), + ) // Call the method. peer.handleNewPendingChannel(req)