From 88ba7293827b1942c20232aa2727c1efeea4fddf Mon Sep 17 00:00:00 2001 From: Matthias Fasching <5011972+fasmat@users.noreply.github.com> Date: Thu, 8 Aug 2024 15:06:05 +0000 Subject: [PATCH] Add sleep to make data race less likely (#6231) ## Motivation This adds sleeps to tests in the `fetch` package to hopefully make data races less likely. --- fetch/fetch_test.go | 2 -- fetch/p2p_test.go | 8 +++++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/fetch/fetch_test.go b/fetch/fetch_test.go index 00599bd5d4..8a525ed8c7 100644 --- a/fetch/fetch_test.go +++ b/fetch/fetch_test.go @@ -169,8 +169,6 @@ func TestFetch_RequestHashBatchFromPeers(t *testing.T) { for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { - t.Parallel() - f := createFetch(t) f.cfg.MaxRetriesForRequest = 0 peer := p2p.Peer("buddy") diff --git a/fetch/p2p_test.go b/fetch/p2p_test.go index a2de466a6d..a9dc85a825 100644 --- a/fetch/p2p_test.go +++ b/fetch/p2p_test.go @@ -90,7 +90,6 @@ func createP2PFetch( ) (*testP2PFetch, context.Context) { lg := zaptest.NewLogger(t) ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) - t.Cleanup(cancel) serverHost, err := p2p.AutoStart(ctx, lg, p2pCfg(t), []byte{}, []byte{}) require.NoError(t, err) @@ -100,6 +99,13 @@ func createP2PFetch( require.NoError(t, err) t.Cleanup(func() { assert.NoError(t, clientHost.Stop()) }) + t.Cleanup(func() { + cancel() + time.Sleep(10 * time.Millisecond) + // mafa: p2p internally uses a global logger this should prevent logging after + // the test ends (send PR with fix to libp2p/go-libp2p-pubsub) (go loop in pubsub.go) + }) + var sqlOpts []sql.Opt if sqlCache { sqlOpts = []sql.Opt{sql.WithQueryCache(true)}