Skip to content

Commit

Permalink
Add sleep to make data race less likely (#6231)
Browse files Browse the repository at this point in the history
## Motivation

This adds sleeps to tests in the `fetch` package to hopefully make data races less likely.
  • Loading branch information
fasmat committed Aug 8, 2024
1 parent ef93b78 commit 88ba729
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 0 additions & 2 deletions fetch/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 7 additions & 1 deletion fetch/p2p_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)}
Expand Down

0 comments on commit 88ba729

Please sign in to comment.