Skip to content

Commit a18e2d3

Browse files
author
Anil Ambati
committed
[FAB-4087] Fix test failure in dockercontroller
Test_Start is failing intermittently because the function variable 'err' in the Start function was used in a go routine function, which was clobbering the function variable, only in cases the go routine was able to finish before the err is returned by the Start function. The fix is to use a local variable in the go routine function. Change-Id: Ibbf0f4e1b551020554ff0b06c2c16bc0f39dbc60 Signed-off-by: Anil Ambati <[email protected]>
1 parent e045b7c commit a18e2d3

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

core/container/dockercontroller/dockercontroller.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,9 @@ func (vm *DockerVM) Start(ctxt context.Context, ccid ccintf.CCID,
267267
go func() {
268268
// AttachToContainer will fire off a message on the "attached" channel once the
269269
// attachment completes, and then block until the container is terminated.
270-
err = client.AttachToContainer(docker.AttachToContainerOptions{
270+
// The returned error is not used outside the scope of this function. Assign the
271+
// error to a local variable to prevent clobbering the function variable 'err'.
272+
err := client.AttachToContainer(docker.AttachToContainerOptions{
271273
Container: containerID,
272274
OutputStream: w,
273275
ErrorStream: w,

core/container/dockercontroller/dockercontroller_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ func Test_Start(t *testing.T) {
125125
spec := &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_GOLANG,
126126
ChaincodeId: &pb.ChaincodeID{Name: "ex01", Path: chaincodePath},
127127
Input: &pb.ChaincodeInput{Args: util.ToChaincodeArgs("f")}}
128-
codePackage, err1 := platforms.GetDeploymentPayload(spec)
129-
if err1 != nil {
128+
codePackage, err := platforms.GetDeploymentPayload(spec)
129+
if err != nil {
130130
t.Fatal()
131131
}
132132
cds := &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec, CodePackage: codePackage}

0 commit comments

Comments
 (0)