Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions pkg/file/joiner/joiner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ func TestJoinerSingleChunk(t *testing.T) {

store := inmemchunkstore.New()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

// create the chunk to
mockAddrHex := fmt.Sprintf("%064s", "2a")
Expand Down Expand Up @@ -95,8 +94,7 @@ func TestJoinerDecryptingStore_NormalChunk(t *testing.T) {

st := inmemchunkstore.New()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

// create the chunk to
mockAddrHex := fmt.Sprintf("%064s", "2a")
Expand Down Expand Up @@ -134,8 +132,7 @@ func TestJoinerWithReference(t *testing.T) {

st := inmemchunkstore.New()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

// create root chunk and two data chunks referenced in the root chunk
rootChunk := filetest.GenerateTestRandomFileChunk(swarm.ZeroAddress, swarm.ChunkSize*2, swarm.SectionSize*2)
Expand Down Expand Up @@ -185,8 +182,7 @@ func TestJoinerMalformed(t *testing.T) {

store := inmemchunkstore.New()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

subTrie := []byte{8085: 1}
pb := builder.NewPipelineBuilder(ctx, store, false, 0)
Expand Down Expand Up @@ -253,8 +249,7 @@ func TestEncryptDecrypt(t *testing.T) {
if err != nil {
t.Fatal(err)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()
pipe := builder.NewPipelineBuilder(ctx, store, true, 0)
testDataReader := bytes.NewReader(testData)
resultAddress, err := builder.FeedPipeline(ctx, pipe, testDataReader)
Expand Down Expand Up @@ -335,8 +330,7 @@ func TestSeek(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

store := inmemchunkstore.New()
testutil.CleanupCloser(t, store)
Expand Down Expand Up @@ -612,8 +606,7 @@ func TestPrefetch(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

store := inmemchunkstore.New()
testutil.CleanupCloser(t, store)
Expand Down Expand Up @@ -917,8 +910,7 @@ func TestJoinerIterateChunkAddresses_Encrypted(t *testing.T) {
if err != nil {
t.Fatal(err)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()
pipe := builder.NewPipelineBuilder(ctx, store, true, 0)
testDataReader := bytes.NewReader(testData)
resultAddress, err := builder.FeedPipeline(ctx, pipe, testDataReader)
Expand Down Expand Up @@ -1072,8 +1064,7 @@ func TestJoinerRedundancy(t *testing.T) {
},
} {
t.Run(fmt.Sprintf("redundancy=%d encryption=%t", tc.rLevel, tc.encryptChunk), func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()
shardCnt := tc.rLevel.GetMaxShards()
parityCnt := tc.rLevel.GetParities(shardCnt)
if tc.encryptChunk {
Expand Down
3 changes: 1 addition & 2 deletions pkg/file/splitter/internal/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ func TestSplitterJobPartialSingleChunk(t *testing.T) {

store := inmemchunkstore.New()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

data := []byte("foo")
j := internal.NewSimpleSplitterJob(ctx, store, int64(len(data)), false)
Expand Down
45 changes: 15 additions & 30 deletions pkg/p2p/libp2p/connections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ func TestAddresses(t *testing.T) {
func TestConnectDisconnect(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{libp2pOpts: libp2p.Options{
FullNode: true,
Expand Down Expand Up @@ -88,8 +87,7 @@ func TestConnectDisconnect(t *testing.T) {
func TestConnectToLightPeer(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s1, _ := newService(t, 1, libp2pServiceOpts{libp2pOpts: libp2p.Options{
FullNode: false,
Expand All @@ -110,8 +108,7 @@ func TestConnectToLightPeer(t *testing.T) {
func TestLightPeerLimit(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

var (
limit = 3
Expand Down Expand Up @@ -160,8 +157,7 @@ func TestStreamsMaxIncomingLimit(t *testing.T) {

maxIncomingStreams := 5000

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{libp2pOpts: libp2p.Options{
FullNode: true,
Expand Down Expand Up @@ -283,8 +279,7 @@ func TestStreamsMaxIncomingLimit(t *testing.T) {
func TestDoubleConnect(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{libp2pOpts: libp2p.Options{
FullNode: true,
Expand All @@ -311,8 +306,7 @@ func TestDoubleConnect(t *testing.T) {
func TestDoubleDisconnect(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{libp2pOpts: libp2p.Options{
FullNode: true,
Expand Down Expand Up @@ -347,8 +341,7 @@ func TestDoubleDisconnect(t *testing.T) {
func TestMultipleConnectDisconnect(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{libp2pOpts: libp2p.Options{
FullNode: true,
Expand Down Expand Up @@ -392,8 +385,7 @@ func TestMultipleConnectDisconnect(t *testing.T) {
func TestConnectDisconnectOnAllAddresses(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{libp2pOpts: libp2p.Options{
FullNode: true,
Expand Down Expand Up @@ -426,8 +418,7 @@ func TestConnectDisconnectOnAllAddresses(t *testing.T) {
func TestDoubleConnectOnAllAddresses(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{
notifier: mockNotifier(noopCf, noopDf, true),
Expand Down Expand Up @@ -471,8 +462,7 @@ func TestDoubleConnectOnAllAddresses(t *testing.T) {
func TestDifferentNetworkIDs(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s1, _ := newService(t, 1, libp2pServiceOpts{})
s2, _ := newService(t, 2, libp2pServiceOpts{})
Expand All @@ -490,8 +480,7 @@ func TestDifferentNetworkIDs(t *testing.T) {
func TestConnectWithEnabledWSTransports(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{
libp2pOpts: libp2p.Options{
Expand Down Expand Up @@ -521,8 +510,7 @@ func TestConnectWithEnabledWSTransports(t *testing.T) {
func TestConnectRepeatHandshake(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{libp2pOpts: libp2p.Options{
FullNode: true,
Expand Down Expand Up @@ -970,8 +958,7 @@ func TestWithDisconnectStreams(t *testing.T) {

const headersRWTimeout = 60 * time.Second

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{libp2pOpts: libp2p.Options{
FullNode: true,
Expand Down Expand Up @@ -1021,8 +1008,7 @@ func TestWithDisconnectStreams(t *testing.T) {
func TestWithBlocklistStreams(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{libp2pOpts: libp2p.Options{
FullNode: true,
Expand Down Expand Up @@ -1073,8 +1059,7 @@ func TestWithBlocklistStreams(t *testing.T) {
func TestUserAgentLogging(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

// use concurrent-safe buffers as handlers are logging concurrently
s1Logs := new(buffer)
Expand Down
9 changes: 3 additions & 6 deletions pkg/p2p/libp2p/headers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ func TestHeaders(t *testing.T) {
"other-key": []byte("other-value"),
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{libp2pOpts: libp2p.Options{
FullNode: true,
Expand Down Expand Up @@ -74,8 +73,7 @@ func TestHeaders(t *testing.T) {
func TestHeaders_empty(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{libp2pOpts: libp2p.Options{
FullNode: true,
Expand Down Expand Up @@ -134,8 +132,7 @@ func TestHeadler(t *testing.T) {
"other-sent-key": []byte("other-sent-value"),
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{libp2pOpts: libp2p.Options{
FullNode: true,
Expand Down
24 changes: 8 additions & 16 deletions pkg/p2p/libp2p/protocols_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import (
func TestNewStream(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{libp2pOpts: libp2p.Options{
FullNode: true,
Expand Down Expand Up @@ -61,8 +60,7 @@ func TestNewStream(t *testing.T) {
func TestNewStream_OnlyFull(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{libp2pOpts: libp2p.Options{
FullNode: true,
Expand Down Expand Up @@ -101,8 +99,7 @@ func TestNewStream_OnlyFull(t *testing.T) {
func TestNewStream_Mixed(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{libp2pOpts: libp2p.Options{
FullNode: true,
Expand Down Expand Up @@ -140,8 +137,7 @@ func TestNewStream_Mixed(t *testing.T) {
func TestNewStreamMulti(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{libp2pOpts: libp2p.Options{
FullNode: true,
Expand Down Expand Up @@ -190,8 +186,7 @@ func TestNewStreamMulti(t *testing.T) {
func TestNewStream_errNotSupported(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{libp2pOpts: libp2p.Options{
FullNode: true,
Expand Down Expand Up @@ -229,8 +224,7 @@ func TestNewStream_errNotSupported(t *testing.T) {
func TestNewStream_semanticVersioning(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{libp2pOpts: libp2p.Options{
FullNode: true,
Expand Down Expand Up @@ -292,8 +286,7 @@ func TestNewStream_semanticVersioning(t *testing.T) {
func TestDisconnectError(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{libp2pOpts: libp2p.Options{
FullNode: true,
Expand Down Expand Up @@ -324,8 +317,7 @@ func TestDisconnectError(t *testing.T) {
func TestConnectDisconnectEvents(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{libp2pOpts: libp2p.Options{
FullNode: true,
Expand Down
6 changes: 2 additions & 4 deletions pkg/p2p/libp2p/tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,13 @@ func TestTracing(t *testing.T) {

addr := serviceUnderlayAddress(t, s1)

connectContext, connectCancel := context.WithCancel(context.Background())
defer connectCancel()
connectContext := t.Context()

if _, err := s2.Connect(connectContext, addr); err != nil {
t.Fatal(err)
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

span, _, ctx := tracer2.StartSpanFromContext(ctx, "test-p2p-client", nil)
defer span.Finish()
Expand Down
Loading