github.com/yous1230/fabric@v2.0.0-beta.0.20191224111736-74345bee6ac2+incompatible/core/scc/inprocstream_test.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package scc 8 9 import ( 10 "testing" 11 12 pb "github.com/hyperledger/fabric-protos-go/peer" 13 "github.com/stretchr/testify/assert" 14 ) 15 16 func TestSend(t *testing.T) { 17 ch := make(chan *pb.ChaincodeMessage) 18 19 stream := newInProcStream(ch, ch) 20 21 //good send (non-blocking send and receive) 22 msg := &pb.ChaincodeMessage{} 23 go stream.Send(msg) 24 msg2, _ := stream.Recv() 25 assert.Equal(t, msg, msg2, "send != recv") 26 27 //close the channel 28 close(ch) 29 30 //bad send, should panic, unblock and return error 31 err := stream.Send(msg) 32 assert.NotNil(t, err, "should have errored on panic") 33 } 34 35 func TestRecvChannelClosedError(t *testing.T) { 36 ch := make(chan *pb.ChaincodeMessage) 37 38 stream := newInProcStream(ch, ch) 39 40 // Close the channel 41 close(ch) 42 43 // Trying to call a closed receive channel should return an error 44 _, err := stream.Recv() 45 if assert.Error(t, err, "Should return an error") { 46 assert.Contains(t, err.Error(), "channel is closed") 47 } 48 }