-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-12516] GetBlock: Close() ledger iterator
This change set ensures the ledger iterator is closed in GetBlock method Change-Id: I294cfe1ba94a6f11b266184f01a30be6c5780dff Signed-off-by: yacovm <yacovm@il.ibm.com>
- Loading branch information
Showing
2 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package blockledger_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hyperledger/fabric/common/deliver/mock" | ||
"github.com/hyperledger/fabric/common/ledger/blockledger" | ||
"github.com/hyperledger/fabric/protos/common" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestClose(t *testing.T) { | ||
for _, testCase := range []struct { | ||
name string | ||
status common.Status | ||
isIteratorNil bool | ||
expectedCloseCount int | ||
}{ | ||
{ | ||
name: "nil iterator", | ||
isIteratorNil: true, | ||
}, | ||
{ | ||
name: "Next() fails", | ||
status: common.Status_INTERNAL_SERVER_ERROR, | ||
expectedCloseCount: 1, | ||
}, | ||
{ | ||
name: "Next() succeeds", | ||
status: common.Status_SUCCESS, | ||
expectedCloseCount: 1, | ||
}, | ||
} { | ||
t.Run(testCase.name, func(t *testing.T) { | ||
var iterator *mock.BlockIterator | ||
reader := &mock.BlockReader{} | ||
if !testCase.isIteratorNil { | ||
iterator = &mock.BlockIterator{} | ||
iterator.NextReturns(&common.Block{}, testCase.status) | ||
reader.IteratorReturns(iterator, 1) | ||
} | ||
|
||
blockledger.GetBlock(reader, 1) | ||
if !testCase.isIteratorNil { | ||
assert.Equal(t, testCase.expectedCloseCount, iterator.CloseCallCount()) | ||
} | ||
}) | ||
} | ||
} |