@@ -156,6 +156,7 @@ func TestTxnVersions(t *testing.T) {
156156 }
157157
158158 checkIterator := func (itr * Iterator , i int ) {
159+ defer itr .Close ()
159160 count := 0
160161 for itr .Rewind (); itr .Valid (); itr .Next () {
161162 item := itr .Item ()
@@ -225,12 +226,14 @@ func TestTxnVersions(t *testing.T) {
225226 opt .AllVersions = true
226227 itr = txn .NewIterator (opt )
227228 checkAllVersions (itr , i )
229+ itr .Close ()
228230
229231 opt = DefaultIteratorOptions
230232 opt .AllVersions = true
231233 opt .Reverse = true
232234 itr = txn .NewIterator (opt )
233235 checkAllVersions (itr , i )
236+ itr .Close ()
234237
235238 txn .Discard ()
236239 }
@@ -352,6 +355,7 @@ func TestTxnIterationEdgeCase(t *testing.T) {
352355 require .Equal (t , uint64 (4 ), db .orc .readTs ())
353356
354357 checkIterator := func (itr * Iterator , expected []string ) {
358+ defer itr .Close ()
355359 var i int
356360 for itr .Rewind (); itr .Valid (); itr .Next () {
357361 item := itr .Item ()
@@ -435,6 +439,7 @@ func TestTxnIterationEdgeCase2(t *testing.T) {
435439 require .Equal (t , uint64 (4 ), db .orc .readTs ())
436440
437441 checkIterator := func (itr * Iterator , expected []string ) {
442+ defer itr .Close ()
438443 var i int
439444 for itr .Rewind (); itr .Valid (); itr .Next () {
440445 item := itr .Item ()
@@ -463,6 +468,7 @@ func TestTxnIterationEdgeCase2(t *testing.T) {
463468 itr .Seek (kc )
464469 require .True (t , itr .Valid ())
465470 require .Equal (t , itr .item .Key (), kc )
471+ itr .Close ()
466472
467473 itr = txn .NewIterator (rev )
468474 itr .Seek (ka )
@@ -471,6 +477,7 @@ func TestTxnIterationEdgeCase2(t *testing.T) {
471477 itr .Seek (kc )
472478 require .True (t , itr .Valid ())
473479 require .Equal (t , itr .item .Key (), kc )
480+ itr .Close ()
474481
475482 txn .readTs = 3
476483 itr = txn .NewIterator (DefaultIteratorOptions )
@@ -537,6 +544,7 @@ func TestTxnIterationEdgeCase3(t *testing.T) {
537544 itr .Seek ([]byte ("ac" ))
538545 require .True (t , itr .Valid ())
539546 require .Equal (t , itr .item .Key (), kc )
547+ itr .Close ()
540548
541549 // Keys: "abc", "ade"
542550 // Read pending writes.
@@ -558,6 +566,7 @@ func TestTxnIterationEdgeCase3(t *testing.T) {
558566 itr .Seek ([]byte ("ad" ))
559567 require .True (t , itr .Valid ())
560568 require .Equal (t , itr .item .Key (), kd )
569+ itr .Close ()
561570
562571 itr = txn .NewIterator (rev )
563572 itr .Seek ([]byte ("ac" ))
@@ -576,6 +585,7 @@ func TestTxnIterationEdgeCase3(t *testing.T) {
576585 itr .Seek ([]byte ("ad" ))
577586 require .True (t , itr .Valid ())
578587 require .Equal (t , itr .item .Key (), kc )
588+ itr .Close ()
579589
580590 // Keys: "abc", "ade"
581591 itr = txn2 .NewIterator (rev )
@@ -595,6 +605,7 @@ func TestTxnIterationEdgeCase3(t *testing.T) {
595605 itr .Seek ([]byte ("ac" ))
596606 require .True (t , itr .Valid ())
597607 require .Equal (t , itr .item .Key (), kb )
608+ itr .Close ()
598609 })
599610}
600611
@@ -630,6 +641,7 @@ func TestIteratorAllVersionsWithDeleted(t *testing.T) {
630641 // Verify that deleted shows up when AllVersions is set.
631642 err = db .View (func (txn * Txn ) error {
632643 it := txn .NewIterator (opts )
644+ defer it .Close ()
633645 var count int
634646 for it .Rewind (); it .Valid (); it .Next () {
635647 count ++
@@ -670,6 +682,7 @@ func TestIteratorAllVersionsWithDeleted2(t *testing.T) {
670682 // Verify that deleted shows up when AllVersions is set.
671683 err := db .View (func (txn * Txn ) error {
672684 it := txn .NewIterator (opts )
685+ defer it .Close ()
673686 var count int
674687 for it .Rewind (); it .Valid (); it .Next () {
675688 item := it .Item ()
0 commit comments