Skip to content

Commit

Permalink
[FAB-4087] Fix test failure in dockercontroller
Browse files Browse the repository at this point in the history
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 <aambati@us.ibm.com>
  • Loading branch information
Anil Ambati committed May 23, 2017
1 parent e045b7c commit a18e2d3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion core/container/dockercontroller/dockercontroller.go
Expand Up @@ -267,7 +267,9 @@ func (vm *DockerVM) Start(ctxt context.Context, ccid ccintf.CCID,
go func() {
// AttachToContainer will fire off a message on the "attached" channel once the
// attachment completes, and then block until the container is terminated.
err = client.AttachToContainer(docker.AttachToContainerOptions{
// The returned error is not used outside the scope of this function. Assign the
// error to a local variable to prevent clobbering the function variable 'err'.
err := client.AttachToContainer(docker.AttachToContainerOptions{
Container: containerID,
OutputStream: w,
ErrorStream: w,
Expand Down
4 changes: 2 additions & 2 deletions core/container/dockercontroller/dockercontroller_test.go
Expand Up @@ -125,8 +125,8 @@ func Test_Start(t *testing.T) {
spec := &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_GOLANG,
ChaincodeId: &pb.ChaincodeID{Name: "ex01", Path: chaincodePath},
Input: &pb.ChaincodeInput{Args: util.ToChaincodeArgs("f")}}
codePackage, err1 := platforms.GetDeploymentPayload(spec)
if err1 != nil {
codePackage, err := platforms.GetDeploymentPayload(spec)
if err != nil {
t.Fatal()
}
cds := &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec, CodePackage: codePackage}
Expand Down

0 comments on commit a18e2d3

Please sign in to comment.