Skip to content

Commit

Permalink
all: run perfsprint
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorropo committed Dec 8, 2023
1 parent ba5ba1a commit b50da98
Show file tree
Hide file tree
Showing 60 changed files with 161 additions and 142 deletions.
5 changes: 3 additions & 2 deletions bitswap/bitswap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bitswap_test
import (
"bytes"
"context"
"errors"
"fmt"
"os"
"sync"
Expand Down Expand Up @@ -432,10 +433,10 @@ func TestBasicBitswap(t *testing.T) {
// peer should no longer keep second peer's want
if err = tu.WaitFor(ctx, func() error {
if len(instances[2].Exchange.WantlistForPeer(instances[1].Peer)) != 0 {
return fmt.Errorf("should have no items in other peers wantlist")
return errors.New("should have no items in other peers wantlist")
}
if len(instances[1].Exchange.GetWantlist()) != 0 {
return fmt.Errorf("shouldnt have anything in wantlist")
return errors.New("shouldnt have anything in wantlist")
}
return nil
}); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion bitswap/client/bitswap_with_sessions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client_test

import (
"context"
"errors"
"fmt"
"testing"
"time"
Expand Down Expand Up @@ -489,7 +490,7 @@ func TestWantlistClearsOnCancel(t *testing.T) {

if err := tu.WaitFor(ctx, func() error {
if len(a.Exchange.GetWantlist()) > 0 {
return fmt.Errorf("expected empty wantlist")
return errors.New("expected empty wantlist")
}
return nil
}); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package messagequeue

import (
"context"
"fmt"
"errors"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -342,7 +342,7 @@ func TestDontHaveTimeoutMgrUsesDefaultTimeoutIfPingError(t *testing.T) {
tr := timeoutRecorder{}
clock := clock.NewMock()
pinged := make(chan struct{})
pc := &mockPeerConn{latency: latency, clock: clock, pinged: pinged, err: fmt.Errorf("ping error")}
pc := &mockPeerConn{latency: latency, clock: clock, pinged: pinged, err: errors.New("ping error")}
timeoutsTriggered := make(chan struct{})

dhtm := newDontHaveTimeoutMgrWithParams(pc, tr.onTimeout,
Expand Down
4 changes: 2 additions & 2 deletions bitswap/client/internal/messagequeue/messagequeue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package messagequeue

import (
"context"
"fmt"
"errors"
"math"
"math/rand"
"sync"
Expand Down Expand Up @@ -40,7 +40,7 @@ func (fmn *fakeMessageNetwork) NewMessageSender(context.Context, peer.ID, *bsnet
func (fms *fakeMessageNetwork) Self() peer.ID { return "" }
func (fms *fakeMessageNetwork) Latency(peer.ID) time.Duration { return 0 }
func (fms *fakeMessageNetwork) Ping(context.Context, peer.ID) ping.Result {
return ping.Result{Error: fmt.Errorf("ping error")}
return ping.Result{Error: errors.New("ping error")}
}

type fakeDontHaveTimeoutMgr struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func (rpm *receivedProviderMessage) handle(pqm *ProviderQueryManager) {
}

func (fpqm *finishedProviderQueryMessage) debugMessage() string {
return fmt.Sprintf("Finished Provider Query on cid: %s", fpqm.k.String())
return "Finished Provider Query on cid: " + fpqm.k.String()
}

func (fpqm *finishedProviderQueryMessage) handle(pqm *ProviderQueryManager) {
Expand All @@ -372,7 +372,7 @@ func (fpqm *finishedProviderQueryMessage) handle(pqm *ProviderQueryManager) {
}

func (npqm *newProvideQueryMessage) debugMessage() string {
return fmt.Sprintf("New Provider Query on cid: %s", npqm.k.String())
return "New Provider Query on cid: " + npqm.k.String()
}

func (npqm *newProvideQueryMessage) handle(pqm *ProviderQueryManager) {
Expand Down Expand Up @@ -407,7 +407,7 @@ func (npqm *newProvideQueryMessage) handle(pqm *ProviderQueryManager) {
}

func (crm *cancelRequestMessage) debugMessage() string {
return fmt.Sprintf("Cancel provider query on cid: %s", crm.k.String())
return "Cancel provider query on cid: " + crm.k.String()
}

func (crm *cancelRequestMessage) handle(pqm *ProviderQueryManager) {
Expand Down
10 changes: 5 additions & 5 deletions bitswap/client/internal/sessionmanager/sessionmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package sessionmanager

import (
"context"
"fmt"
"strconv"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestReceiveFrom(t *testing.T) {
pm := &fakePeerManager{}
sm := New(ctx, sessionFactory, sim, peerManagerFactory, bpm, pm, notif, "")

p := peer.ID(fmt.Sprint(123))
p := peer.ID(strconv.Itoa(123))
block := blocks.NewBlock([]byte("block"))

firstSession := sm.NewSession(ctx, time.Second, delay.Fixed(time.Minute)).(*fakeSession)
Expand Down Expand Up @@ -169,7 +169,7 @@ func TestReceiveBlocksWhenManagerShutdown(t *testing.T) {
pm := &fakePeerManager{}
sm := New(ctx, sessionFactory, sim, peerManagerFactory, bpm, pm, notif, "")

p := peer.ID(fmt.Sprint(123))
p := peer.ID(strconv.Itoa(123))
block := blocks.NewBlock([]byte("block"))

firstSession := sm.NewSession(ctx, time.Second, delay.Fixed(time.Minute)).(*fakeSession)
Expand Down Expand Up @@ -203,7 +203,7 @@ func TestReceiveBlocksWhenSessionContextCancelled(t *testing.T) {
pm := &fakePeerManager{}
sm := New(ctx, sessionFactory, sim, peerManagerFactory, bpm, pm, notif, "")

p := peer.ID(fmt.Sprint(123))
p := peer.ID(strconv.Itoa(123))
block := blocks.NewBlock([]byte("block"))

firstSession := sm.NewSession(ctx, time.Second, delay.Fixed(time.Minute)).(*fakeSession)
Expand Down Expand Up @@ -239,7 +239,7 @@ func TestShutdown(t *testing.T) {
pm := &fakePeerManager{}
sm := New(ctx, sessionFactory, sim, peerManagerFactory, bpm, pm, notif, "")

p := peer.ID(fmt.Sprint(123))
p := peer.ID(strconv.Itoa(123))
block := blocks.NewBlock([]byte("block"))
cids := []cid.Cid{block.Cid()}
firstSession := sm.NewSession(ctx, time.Second, delay.Fixed(time.Minute)).(*fakeSession)
Expand Down
3 changes: 1 addition & 2 deletions bitswap/client/internal/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package internal

import (
"context"
"fmt"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"
)

func StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) {
return otel.Tracer("go-bitswap").Start(ctx, fmt.Sprintf("Bitswap.%s", name), opts...)
return otel.Tracer("go-bitswap").Start(ctx, "Bitswap."+name, opts...)
}
4 changes: 2 additions & 2 deletions bitswap/internal/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package testutil

import (
"crypto/rand"
"fmt"
"strconv"

"github.com/ipfs/boxo/bitswap/client/wantlist"
bsmsg "github.com/ipfs/boxo/bitswap/message"
Expand Down Expand Up @@ -62,7 +62,7 @@ func GeneratePeers(n int) []peer.ID {
peerIds := make([]peer.ID, 0, n)
for i := 0; i < n; i++ {
peerSeq++
p := peer.ID(fmt.Sprint(peerSeq))
p := peer.ID(strconv.Itoa(peerSeq))
peerIds = append(peerIds, p)
}
return peerIds
Expand Down
3 changes: 1 addition & 2 deletions bitswap/internal/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package internal

import (
"context"
"fmt"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"
)

func StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) {
return otel.Tracer("go-bitswap").Start(ctx, fmt.Sprintf("Bitswap.%s", name), opts...)
return otel.Tracer("go-bitswap").Start(ctx, "Bitswap."+name, opts...)
}
3 changes: 2 additions & 1 deletion bitswap/network/ipfs_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package network_test

import (
"context"
"errors"
"fmt"
"sync"
"testing"
Expand Down Expand Up @@ -69,7 +70,7 @@ func (r *receiver) PeerDisconnected(p peer.ID) {
r.connectionEvent <- false
}

var errMockNetErr = fmt.Errorf("network err")
var errMockNetErr = errors.New("network err")

type ErrStream struct {
network.Stream
Expand Down
4 changes: 2 additions & 2 deletions bitswap/server/internal/decision/blockstoremanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package decision

import (
"context"
"fmt"
"errors"
"sync"

bstore "github.com/ipfs/boxo/blockstore"
Expand Down Expand Up @@ -77,7 +77,7 @@ func (bsm *blockstoreManager) addJob(ctx context.Context, job func()) error {
case <-ctx.Done():
return ctx.Err()
case <-bsm.stopChan:
return fmt.Errorf("shutting down")
return errors.New("shutting down")
case bsm.jobs <- job:
bsm.pendingGauge.Inc()
return nil
Expand Down
3 changes: 2 additions & 1 deletion bitswap/server/internal/decision/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/binary"
"errors"
"fmt"
"strconv"
"strings"
"sync"
"testing"
Expand Down Expand Up @@ -1647,7 +1648,7 @@ func TestWantlistGrowsToLimit(t *testing.T) {
// Send in two messages to test reslicing.
m := message.New(false)
for j := limit; j != 0; j-- {
m.AddEntry(blocks.NewBlock([]byte(fmt.Sprint(j))).Cid(), 0, pb.Message_Wantlist_Block, true)
m.AddEntry(blocks.NewBlock([]byte(strconv.Itoa(j))).Cid(), 0, pb.Message_Wantlist_Block, true)
}
warsaw.Engine.MessageReceived(ctx, riga.Peer, m)

Expand Down
3 changes: 1 addition & 2 deletions blockservice/internal/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package internal

import (
"context"
"fmt"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"
)

func StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) {
return otel.Tracer("go-blockservice").Start(ctx, fmt.Sprintf("Blockservice.%s", name), opts...)
return otel.Tracer("go-blockservice").Start(ctx, "Blockservice."+name, opts...)
}
11 changes: 6 additions & 5 deletions files/serialfile_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package files

import (
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -125,22 +126,22 @@ testInputs:
// root node.
if path == "" {
if rootFound {
return fmt.Errorf("found root twice")
return errors.New("found root twice")
}
if sf != nd {
return fmt.Errorf("wrong root")
return errors.New("wrong root")
}
rootFound = true
return nil
}
actualPaths = append(actualPaths, path)
if !hidden && isFullPathHidden(path) {
return fmt.Errorf("found a hidden file")
return errors.New("found a hidden file")
}
components := filepath.SplitList(path)
for i := range components {
if fileFilter.Rules.MatchesPath(filepath.Join(components[:i+1]...)) {
return fmt.Errorf("found a file that should be excluded")
return errors.New("found a file that should be excluded")
}
}

Expand All @@ -152,7 +153,7 @@ testInputs:

switch nd := nd.(type) {
case *Symlink:
return fmt.Errorf("didn't expect a symlink")
return errors.New("didn't expect a symlink")
case Directory:
if data != "" {
return fmt.Errorf("expected a directory at %q", path)
Expand Down
7 changes: 4 additions & 3 deletions gateway/assets/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package assets
import (
"encoding/hex"
"fmt"
"strconv"

"github.com/ipld/go-ipld-prime/datamodel"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
Expand Down Expand Up @@ -55,21 +56,21 @@ func ParseNode(node datamodel.Node) (*ParsedNode, error) {
return nil, err
}

dag.Keys = append(dag.Keys, &ParsedNode{Value: fmt.Sprintf("%d", k)})
dag.Keys = append(dag.Keys, &ParsedNode{Value: strconv.FormatInt(k, 10)})
dag.Values = append(dag.Values, vd)
}
case datamodel.Kind_Bool:
v, err := node.AsBool()
if err != nil {
return nil, err
}
dag.Value = fmt.Sprintf("%t", v)
dag.Value = strconv.FormatBool(v)
case datamodel.Kind_Int:
v, err := node.AsInt()
if err != nil {
return nil, err
}
dag.Value = fmt.Sprintf("%d", v)
dag.Value = strconv.FormatInt(v, 10)
case datamodel.Kind_Float:
v, err := node.AsFloat()
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions gateway/blocks_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (bb *BlocksBackend) Get(ctx context.Context, path path.ImmutablePath, range
return ContentPathMetadata{}, nil, fmt.Errorf("could not get cumulative directory DAG size: %w", err)
}
if sz < 0 {
return ContentPathMetadata{}, nil, fmt.Errorf("directory cumulative DAG size cannot be negative")
return ContentPathMetadata{}, nil, errors.New("directory cumulative DAG size cannot be negative")

Check warning on line 208 in gateway/blocks_backend.go

View check run for this annotation

Codecov / codecov/patch

gateway/blocks_backend.go#L208

Added line #L208 was not covered by tests
}
return md, NewGetResponseFromDirectoryListing(uint64(sz), dir.EnumLinksAsync(ctx), nil), nil
}
Expand Down Expand Up @@ -287,7 +287,7 @@ func (bb *BlocksBackend) Head(ctx context.Context, path path.ImmutablePath) (Con
return md, NewHeadResponseForFile(f, sz), nil
}

return ContentPathMetadata{}, nil, fmt.Errorf("unsupported UnixFS file type")
return ContentPathMetadata{}, nil, errors.New("unsupported UnixFS file type")

Check warning on line 290 in gateway/blocks_backend.go

View check run for this annotation

Codecov / codecov/patch

gateway/blocks_backend.go#L290

Added line #L290 was not covered by tests
}

// emptyRoot is a CAR root with the empty identity CID. CAR files are recommended
Expand Down Expand Up @@ -335,7 +335,7 @@ func (bb *BlocksBackend) GetCAR(ctx context.Context, p path.ImmutablePath, param
}

if p.Namespace() != path.IPFSNamespace {
return ContentPathMetadata{}, nil, fmt.Errorf("path does not have /ipfs/ prefix")
return ContentPathMetadata{}, nil, errors.New("path does not have /ipfs/ prefix")

Check warning on line 338 in gateway/blocks_backend.go

View check run for this annotation

Codecov / codecov/patch

gateway/blocks_backend.go#L338

Added line #L338 was not covered by tests
}

r, w := io.Pipe()
Expand Down Expand Up @@ -482,7 +482,7 @@ func walkGatewaySimpleSelector(ctx context.Context, p path.ImmutablePath, params

fnd, ok := nd.(datamodel.LargeBytesNode)
if !ok {
return fmt.Errorf("could not process file since it did not present as large bytes")
return errors.New("could not process file since it did not present as large bytes")

Check warning on line 485 in gateway/blocks_backend.go

View check run for this annotation

Codecov / codecov/patch

gateway/blocks_backend.go#L485

Added line #L485 was not covered by tests
}
f, err := fnd.AsLargeBytes()
if err != nil {
Expand Down Expand Up @@ -532,7 +532,7 @@ func walkGatewaySimpleSelector(ctx context.Context, p path.ImmutablePath, params

numToRead := 1 + to - from
if numToRead < 0 {
return fmt.Errorf("tried to read less than zero bytes")
return errors.New("tried to read less than zero bytes")

Check warning on line 535 in gateway/blocks_backend.go

View check run for this annotation

Codecov / codecov/patch

gateway/blocks_backend.go#L535

Added line #L535 was not covered by tests
}

if _, err := f.Seek(from, io.SeekStart); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion gateway/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (e *ErrorRetryAfter) Error() string {
text = e.Err.Error()
}
if e.RetryAfter != 0 {
text += fmt.Sprintf(", retry after %s", e.humanizedRoundSeconds())
text += ", retry after " + e.humanizedRoundSeconds()
}
return text
}
Expand Down
Loading

0 comments on commit b50da98

Please sign in to comment.