From 76effdb61829779cc0741a3509d71e332a47d08c Mon Sep 17 00:00:00 2001 From: Mark Rushakoff Date: Fri, 22 Jul 2022 11:34:44 -0400 Subject: [PATCH] Skip long internal/p2p tests in -short mode I added checks against testing.Short for tests that took longer than about one second on my machine. Running with -short reduces the test time of internal/p2p from about 29s to about 5.4s. --- internal/p2p/peermanager_test.go | 4 ++++ internal/p2p/router_test.go | 27 +++++++++++++++++++++++++-- internal/p2p/transport_mconn_test.go | 4 ++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/internal/p2p/peermanager_test.go b/internal/p2p/peermanager_test.go index a1543bf18..3e72c333b 100644 --- a/internal/p2p/peermanager_test.go +++ b/internal/p2p/peermanager_test.go @@ -296,6 +296,10 @@ func TestPeerManager_DialNext(t *testing.T) { } func TestPeerManager_DialNext_Retry(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode") + } + ctx, cancel := context.WithCancel(context.Background()) defer cancel() diff --git a/internal/p2p/router_test.go b/internal/p2p/router_test.go index dd336510c..748731f32 100644 --- a/internal/p2p/router_test.go +++ b/internal/p2p/router_test.go @@ -41,6 +41,10 @@ func echoReactor(ctx context.Context, channel p2p.Channel) { } func TestRouter_Network(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode") + } + ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -162,6 +166,10 @@ func TestRouter_Channel_Basic(t *testing.T) { // Channel tests are hairy to mock, so we use an in-memory network instead. func TestRouter_Channel_SendReceive(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode") + } + ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -224,6 +232,10 @@ func TestRouter_Channel_SendReceive(t *testing.T) { } func TestRouter_Channel_Broadcast(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode") + } + t.Cleanup(leaktest.Check(t)) ctx, cancel := context.WithCancel(context.Background()) @@ -255,6 +267,10 @@ func TestRouter_Channel_Broadcast(t *testing.T) { } func TestRouter_Channel_Wrapper(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode") + } + t.Cleanup(leaktest.Check(t)) ctx, cancel := context.WithCancel(context.Background()) @@ -443,6 +459,11 @@ func TestRouter_AcceptPeers(t *testing.T) { } func TestRouter_AcceptPeers_Errors(t *testing.T) { + if testing.Short() { + // Each subtest takes more than one second due to the time.Sleep call, + // so just skip from the parent test in short mode. + t.Skip("skipping test in short mode") + } for _, err := range []error{io.EOF, context.Canceled, context.DeadlineExceeded} { t.Run(err.Error(), func(t *testing.T) { @@ -480,9 +501,7 @@ func TestRouter_AcceptPeers_Errors(t *testing.T) { router.Stop() mockTransport.AssertExpectations(t) - }) - } } @@ -811,6 +830,10 @@ func TestRouter_EvictPeers(t *testing.T) { } func TestRouter_ChannelCompatability(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode") + } + t.Cleanup(leaktest.Check(t)) ctx, cancel := context.WithCancel(context.Background()) defer cancel() diff --git a/internal/p2p/transport_mconn_test.go b/internal/p2p/transport_mconn_test.go index c478dbe1d..6fafd01ae 100644 --- a/internal/p2p/transport_mconn_test.go +++ b/internal/p2p/transport_mconn_test.go @@ -59,6 +59,10 @@ func TestMConnTransport_AcceptBeforeListen(t *testing.T) { } func TestMConnTransport_AcceptMaxAcceptedConnections(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode") + } + ctx, cancel := context.WithCancel(context.Background()) defer cancel()