Skip to content
This repository has been archived by the owner on Oct 17, 2018. It is now read-only.

Commit

Permalink
Closing migration iterator should close inner iterators (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
xichen2020 committed Jun 19, 2018
1 parent a1db733 commit 3b29579
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions encoding/migration/unaggregated_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ func (it *unaggregatedIterator) Close() {
return
}
it.closed = true
it.msgpackIt.Close()
it.msgpackIt = nil
it.protobufIt.Close()
it.protobufIt = nil
it.msg = encoding.UnaggregatedMessageUnion{}
it.err = nil
}
Expand Down
23 changes: 22 additions & 1 deletion encoding/migration/unaggregated_iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -813,8 +813,29 @@ func TestUnaggregatedIteratorNextOnClose(t *testing.T) {
require.False(t, it.Next())
require.True(t, iterator.closed)
require.Equal(t, encoding.UnaggregatedMessageUnion{}, iterator.msg)
require.Nil(t, it.Err())

// Verify that closing a second time is a no op.
it.Close()
}

func TestUnaggregatedIteratorClose(t *testing.T) {
it := NewUnaggregatedIterator(
nil,
msgpack.NewUnaggregatedIteratorOptions(),
protobuf.NewUnaggregatedOptions(),
)
require.False(t, it.(*unaggregatedIterator).closed)
require.NotNil(t, it.(*unaggregatedIterator).msgpackIt)
require.NotNil(t, it.(*unaggregatedIterator).protobufIt)

it.Close()
require.True(t, it.(*unaggregatedIterator).closed)
require.Nil(t, it.(*unaggregatedIterator).msgpackIt)
require.Nil(t, it.(*unaggregatedIterator).protobufIt)

// Verify that closing a second time is a no op.
it.Close()
require.True(t, it.(*unaggregatedIterator).closed)
require.Nil(t, it.(*unaggregatedIterator).msgpackIt)
require.Nil(t, it.(*unaggregatedIterator).protobufIt)
}

0 comments on commit 3b29579

Please sign in to comment.