Skip to content

Commit 00eb7c9

Browse files
committed
[FAB-3352] No need to initialize grpc in CSCC tests
CSCC configure_test.go leverages mocking framewrk to test CSCC invokations, while each test initializes grpc server while not real need for this. Current commit takes care to make tests stop initializing grpc server and clean up the test from non relevant code. Change-Id: Iec29046f644603c8412a8ea0da648f2d448e5d2f Signed-off-by: Artem Barger <[email protected]>
1 parent d7af6e8 commit 00eb7c9

File tree

1 file changed

+10
-35
lines changed

1 file changed

+10
-35
lines changed

core/scc/cscc/configure_test.go

+10-35
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ package cscc
1717

1818
import (
1919
"fmt"
20-
"net"
2120
"os"
21+
"strings"
2222
"testing"
2323
"time"
2424

25-
"strings"
26-
2725
"github.com/golang/protobuf/proto"
2826
configtxtest "github.com/hyperledger/fabric/common/configtx/test"
2927
"github.com/hyperledger/fabric/common/localmsp"
@@ -45,7 +43,6 @@ import (
4543
"github.com/hyperledger/fabric/protos/utils"
4644
"github.com/spf13/viper"
4745
"github.com/stretchr/testify/assert"
48-
"google.golang.org/grpc"
4946
)
5047

5148
type mockDeliveryClient struct {
@@ -91,22 +88,6 @@ func TestConfigerInit(t *testing.T) {
9188
}
9289
}
9390

94-
func setupEndpoint(t *testing.T) {
95-
peerAddress := peer.GetLocalIP()
96-
if peerAddress == "" {
97-
peerAddress = "0.0.0.0"
98-
}
99-
peerAddress = peerAddress + ":21213"
100-
t.Logf("Local peer IP address: %s", peerAddress)
101-
var opts []grpc.ServerOption
102-
grpcServer := grpc.NewServer(opts...)
103-
getPeerEndpoint := func() (*pb.PeerEndpoint, error) {
104-
return &pb.PeerEndpoint{Id: &pb.PeerID{Name: "cscctestpeer"}, Address: peerAddress}, nil
105-
}
106-
ccStartupTimeout := time.Duration(30000) * time.Millisecond
107-
pb.RegisterChaincodeSupportServer(grpcServer, chaincode.NewChaincodeSupport(getPeerEndpoint, false, ccStartupTimeout))
108-
}
109-
11091
func TestConfigerInvokeJoinChainMissingParams(t *testing.T) {
11192
viper.Set("peer.fileSystemPath", "/tmp/hyperledgertest/")
11293
os.Mkdir("/tmp/hyperledgertest", 0755)
@@ -120,7 +101,6 @@ func TestConfigerInvokeJoinChainMissingParams(t *testing.T) {
120101
t.FailNow()
121102
}
122103

123-
setupEndpoint(t)
124104
// Failed path: Not enough parameters
125105
args := [][]byte{[]byte("JoinChain")}
126106
if res := stub.MockInvoke("2", args); res.Status == shim.OK {
@@ -141,8 +121,6 @@ func TestConfigerInvokeJoinChainWrongParams(t *testing.T) {
141121
t.FailNow()
142122
}
143123

144-
setupEndpoint(t)
145-
146124
// Failed path: wrong parameter type
147125
args := [][]byte{[]byte("JoinChain"), []byte("action")}
148126
if res := stub.MockInvoke("2", args); res.Status == shim.OK {
@@ -152,6 +130,7 @@ func TestConfigerInvokeJoinChainWrongParams(t *testing.T) {
152130

153131
func TestConfigerInvokeJoinChainCorrectParams(t *testing.T) {
154132
viper.Set("peer.fileSystemPath", "/tmp/hyperledgertest/")
133+
viper.Set("chaincode.executetimeout", "3000")
155134
os.Mkdir("/tmp/hyperledgertest", 0755)
156135

157136
peer.MockInitialize()
@@ -162,6 +141,13 @@ func TestConfigerInvokeJoinChainCorrectParams(t *testing.T) {
162141
e := new(PeerConfiger)
163142
stub := shim.NewMockStub("PeerConfiger", e)
164143

144+
peerEndpoint := "localhost:13611"
145+
getPeerEndpoint := func() (*pb.PeerEndpoint, error) {
146+
return &pb.PeerEndpoint{Id: &pb.PeerID{Name: "cscctestpeer"}, Address: peerEndpoint}, nil
147+
}
148+
ccStartupTimeout := time.Duration(30000) * time.Millisecond
149+
chaincode.NewChaincodeSupport(getPeerEndpoint, false, ccStartupTimeout)
150+
165151
// Init the policy checker
166152
policyManagerGetter := &policy.MockChannelPolicyManagerGetter{
167153
Managers: map[string]policies.Manager{
@@ -177,18 +163,9 @@ func TestConfigerInvokeJoinChainCorrectParams(t *testing.T) {
177163
&policy.MockMSPPrincipalGetter{Principal: []byte("Alice")},
178164
)
179165

180-
setupEndpoint(t)
181-
182-
// Initialize gossip service
183-
grpcServer := grpc.NewServer()
184-
socket, err := net.Listen("tcp", fmt.Sprintf("%s:%d", "", 13611))
185-
assert.NoError(t, err)
186-
go grpcServer.Serve(socket)
187-
defer grpcServer.Stop()
188-
189166
identity, _ := mgmt.GetLocalSigningIdentityOrPanic().Serialize()
190167
messageCryptoService := mcs.New(&mcs.MockChannelPolicyManagerGetter{}, localmsp.NewSigner(), mgmt.NewDeserializersManager())
191-
service.InitGossipServiceCustomDeliveryFactory(identity, "localhost:13611", grpcServer, &mockDeliveryClientFactory{}, messageCryptoService)
168+
service.InitGossipServiceCustomDeliveryFactory(identity, peerEndpoint, nil, &mockDeliveryClientFactory{}, messageCryptoService)
192169

193170
// Successful path for JoinChain
194171
blockBytes := mockConfigBlock()
@@ -262,8 +239,6 @@ func TestConfigerInvokeUpdateConfigBlock(t *testing.T) {
262239
&policy.MockMSPPrincipalGetter{Principal: []byte("Alice")},
263240
)
264241

265-
setupEndpoint(t)
266-
267242
sProp, _ := utils.MockSignedEndorserProposalOrPanic("", &pb.ChaincodeSpec{}, []byte("Alice"), []byte("msg1"))
268243
identityDeserializer.Msg = sProp.ProposalBytes
269244
sProp.Signature = sProp.ProposalBytes

0 commit comments

Comments
 (0)