not to use defer when not needed
@@ -2,16 +2,16 @@ package p2p
import (
"github.com/spacemeshos/go-spacemesh/p2p/connectionpool"
- "github.com/spacemeshos/go-spacemesh/p2p/p2pcrypto"
"github.com/spacemeshos/go-spacemesh/p2p/dht"
- "github.com/stretchr/testify/require"
"testing"
"time"
"context"
"errors"
"github.com/gogo/protobuf/proto"
+ "github.com/spacemeshos/go-spacemesh/crypto"
"github.com/spacemeshos/go-spacemesh/p2p/config"
+ "github.com/spacemeshos/go-spacemesh/p2p/message"
"github.com/spacemeshos/go-spacemesh/p2p/net"
"github.com/spacemeshos/go-spacemesh/p2p/node"
"github.com/spacemeshos/go-spacemesh/p2p/pb"
@@ -220,9 +220,6 @@ func TestSwarm_RoundTrip(t *testing.T) {
p1 := p2pTestInstance(t, config.DefaultConfig())
p2 := p2pTestInstance(t, config.DefaultConfig())
- defer p1.Shutdown()
- defer p2.Shutdown()
-
exchan1 := p1.RegisterProtocol(exampleProtocol)
assert.Equal(t, exchan1, p1.protocolHandlers[exampleProtocol])
exchan2 := p2.RegisterProtocol(exampleProtocol)
@@ -232,15 +229,15 @@ func TestSwarm_RoundTrip(t *testing.T) {
sendDirectMessage(t, p2, p1.lNode.PublicKey(), exchan1, true)
sendDirectMessage(t, p1, p2.lNode.PublicKey(), exchan2, true)
+
+ p1.Shutdown()
+ p2.Shutdown()
}
func TestSwarm_MultipleMessages(t *testing.T) {
p1 := p2pTestInstance(t, config.DefaultConfig())
p2 := p2pTestInstance(t, config.DefaultConfig())
- defer p1.Shutdown()
- defer p2.Shutdown()
-
exchan1 := p1.RegisterProtocol(exampleProtocol)
assert.Equal(t, exchan1, p1.protocolHandlers[exampleProtocol])
exchan2 := p2.RegisterProtocol(exampleProtocol)
@@ -256,6 +253,9 @@ func TestSwarm_MultipleMessages(t *testing.T) {
go func() { sendDirectMessage(t, p2, p1.lNode.PublicKey(), exchan1, false); wg.Done() }()
}
wg.Wait()
+
+ p1.Shutdown()
+ p2.Shutdown()
}
type swarmArray struct {
@@ -286,7 +286,6 @@ func TestSwarm_MultipleMessagesFromMultipleSenders(t *testing.T) {
cfg.SwarmConfig.Bootstrap = false
p1 := p2pTestInstance(t, cfg)
- defer p1.Shutdown()
exchan1 := p1.RegisterProtocol(exampleProtocol)
assert.Equal(t, exchan1, p1.protocolHandlers[exampleProtocol])
@@ -329,6 +328,7 @@ func TestSwarm_MultipleMessagesFromMultipleSenders(t *testing.T) {
}()
}
wg.Wait()
+ p1.Shutdown()
sa.clean()
}
@@ -346,7 +346,6 @@ func TestSwarm_MultipleMessagesFromMultipleSendersToMultipleProtocols(t *testing
var wg sync.WaitGroup
p1 := p2pTestInstance(t, cfg)
- defer p1.Shutdown()
var protos []string
@@ -396,6 +395,7 @@ func TestSwarm_MultipleMessagesFromMultipleSendersToMultipleProtocols(t *testing
}()
}
wg.Wait()
+ p1.Shutdown()
sa.clean()
}
