github.com/adnan-c/fabric_e2e_couchdb@v0.6.1-preview.0.20170228180935-21ce6b23cf91/gossip/service/gossip_service_test.go (about) 1 /* 2 Copyright IBM Corp. 2016 All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package service 18 19 import ( 20 "fmt" 21 "net" 22 "sync" 23 "testing" 24 25 "time" 26 27 mockpolicies "github.com/hyperledger/fabric/common/mocks/policies" 28 "github.com/hyperledger/fabric/gossip/api" 29 "github.com/hyperledger/fabric/msp/mgmt" 30 "github.com/hyperledger/fabric/msp/mgmt/testtools" 31 "github.com/hyperledger/fabric/peer/gossip/mcs" 32 "github.com/stretchr/testify/assert" 33 "google.golang.org/grpc" 34 ) 35 36 func TestInitGossipService(t *testing.T) { 37 // Test whenever gossip service is indeed singleton 38 grpcServer := grpc.NewServer() 39 socket, error := net.Listen("tcp", fmt.Sprintf("%s:%d", "", 5611)) 40 assert.NoError(t, error) 41 42 go grpcServer.Serve(socket) 43 defer grpcServer.Stop() 44 45 msptesttools.LoadMSPSetupForTesting("../../msp/sampleconfig") 46 identity, _ := mgmt.GetLocalSigningIdentityOrPanic().Serialize() 47 48 wg := sync.WaitGroup{} 49 wg.Add(10) 50 for i := 0; i < 10; i++ { 51 go func() { 52 InitGossipService(identity, "localhost:5611", grpcServer, mcs.New(&mockpolicies.PolicyManagerMgmt{})) 53 54 wg.Done() 55 }() 56 } 57 wg.Wait() 58 59 defer GetGossipService().Stop() 60 gossip := GetGossipService() 61 62 for i := 0; i < 10; i++ { 63 go func(gossipInstance GossipService) { 64 assert.Equal(t, gossip, GetGossipService()) 65 }(gossip) 66 } 67 68 time.Sleep(time.Second * 2) 69 } 70 71 // Make sure *joinChannelMessage implements the api.JoinChannelMessage 72 func TestJCMInterface(t *testing.T) { 73 _ = api.JoinChannelMessage(&joinChannelMessage{}) 74 }