Skip to content

Commit 222bd57

Browse files
committedJun 19, 2018
[FAB-10709] fix flake in inproccontroller_test
This was caused by several things. - The production code runs in a go routine and the test doesn't wait - The production code was recently changed to stop using the injected test function - The test was using an incorrect matcher Change-Id: Id861d57081ef3260e7faf15e59822c94291b793d Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
1 parent 3436f45 commit 222bd57

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed
 

‎core/container/inproccontroller/inproccontroller.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ func (ipc *inprocContainer) launchInProc(ctxt context.Context, id string, args [
112112
var err error
113113
ccchan := make(chan struct{}, 1)
114114
ccsupportchan := make(chan struct{}, 1)
115+
shimStartInProc := _shimStartInProc // shadow to avoid race in test
115116
go func() {
116117
defer close(ccchan)
117118
inprocLogger.Debugf("chaincode started for %s", id)
@@ -121,12 +122,12 @@ func (ipc *inprocContainer) launchInProc(ctxt context.Context, id string, args [
121122
if env == nil {
122123
env = ipc.env
123124
}
124-
err := shim.StartInProc(env, args, ipc.chaincode, ccRcvPeerSend, peerRcvCCSend)
125+
err := shimStartInProc(env, args, ipc.chaincode, ccRcvPeerSend, peerRcvCCSend)
125126
if err != nil {
126127
err = fmt.Errorf("chaincode-support ended with err: %s", err)
127128
_inprocLoggerErrorf("%s", err)
128129
}
129-
inprocLogger.Debugf("chaincode ended with for %s with err: %s", id, err)
130+
inprocLogger.Debugf("chaincode ended for %s with err: %s", id, err)
130131
}()
131132

132133
go func() {
@@ -138,7 +139,7 @@ func (ipc *inprocContainer) launchInProc(ctxt context.Context, id string, args [
138139
err = fmt.Errorf("chaincode ended with err: %s", err)
139140
_inprocLoggerErrorf("%s", err)
140141
}
141-
inprocLogger.Debugf("chaincode-support ended with for %s with err: %s", id, err)
142+
inprocLogger.Debugf("chaincode-support ended for %s with err: %s", id, err)
142143
}()
143144

144145
select {

‎core/container/inproccontroller/inproccontroller_test.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package inproccontroller
88

99
import (
1010
"errors"
11+
"fmt"
1112
"testing"
1213
"time"
1314

@@ -243,13 +244,14 @@ func TestLaunchprocShimStartInProcErr(t *testing.T) {
243244
return errors.New("error")
244245
}
245246

247+
done := make(chan struct{})
246248
_inprocLoggerErrorfCounter := 0
247249
_inprocLoggerErrorf = func(format string, args ...interface{}) {
248-
_inprocLoggerErrorfCounter = _inprocLoggerErrorfCounter + 1
249-
250-
if _inprocLoggerErrorfCounter == 2 {
250+
_inprocLoggerErrorfCounter++
251+
if _inprocLoggerErrorfCounter == 1 {
251252
assert.Equal(t, format, "%s", "Format is correct")
252-
assert.Equal(t, args[0], "chaincode-support ended with err: error", "content is correct")
253+
assert.Equal(t, fmt.Sprintf("%s", args[0]), "chaincode-support ended with err: error", "content is correct")
254+
close(done)
253255
}
254256
}
255257
mockContext := MockContext{}
@@ -265,6 +267,7 @@ func TestLaunchprocShimStartInProcErr(t *testing.T) {
265267

266268
err := mockInprocContainer.launchInProc(mockContext, "ID", args, env, MockCCSupport{})
267269
assert.Nil(t, err, "err should be nil")
270+
<-done
268271
}
269272

270273
type MockCCSupportErr struct {

0 commit comments

Comments
 (0)
Please sign in to comment.