Skip to content

Commit

Permalink
[FAB-10154] Close RWSetScanner at end of use
Browse files Browse the repository at this point in the history
There is a missing call to Close() after obtaining the RWSetScanner
and iterating over the results, in the private data support
for the endorser plugins.

Change-Id: I645ae82f2e985188b1d526461695aaf24a77674e
Signed-off-by: yacovm <[email protected]>
  • Loading branch information
yacovm committed May 16, 2018
1 parent ec1f138 commit f096ff7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions core/endorser/plugin_endorser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ func (fep *fakeEndorsementPlugin) Init(dependencies ...endorsement.Dependency) e
}

type rwsetScanner struct {
mock.Mock
data []*rwset.TxPvtReadWriteSet
}

Expand All @@ -254,8 +255,8 @@ func (rws *rwsetScanner) NextWithConfig() (*transientstore.EndorserPvtSimulation
}, nil
}

func (*rwsetScanner) Close() {
panic("implement me")
func (rws *rwsetScanner) Close() {
rws.Called()
}

func TestTransientStore(t *testing.T) {
Expand Down Expand Up @@ -312,6 +313,7 @@ func TestTransientStore(t *testing.T) {
scanner := &rwsetScanner{
data: []*rwset.TxPvtReadWriteSet{rws},
}
scanner.On("Close")

transientStore.On("GetTxPvtRWSetByTxid", mock.Anything, mock.Anything).Return(scanner, nil)

Expand All @@ -322,4 +324,5 @@ func TestTransientStore(t *testing.T) {
err = proto.Unmarshal(resp.Payload, txrws)
assert.NoError(t, err)
assert.Equal(t, rws, txrws)
scanner.AssertCalled(t, "Close")
}
1 change: 1 addition & 0 deletions core/endorser/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func (sc *StateContext) GetTransientByTXID(txID string) ([]*rwset.TxPvtReadWrite
if err != nil {
return nil, errors.WithStack(err)
}
defer scanner.Close()
var data []*rwset.TxPvtReadWriteSet
for {
res, err := scanner.NextWithConfig()
Expand Down

0 comments on commit f096ff7

Please sign in to comment.