@@ -695,8 +695,10 @@ func TestIterLeak(t *testing.T) {
695
695
t .Run (fmt .Sprintf ("leak=%t" , leak ), func (t * testing.T ) {
696
696
for _ , flush := range []bool {true , false } {
697
697
t .Run (fmt .Sprintf ("flush=%t" , flush ), func (t * testing.T ) {
698
+ fc := NewFileCache (10 , 100 )
698
699
d , err := Open ("" , testingRandomized (t , & Options {
699
- FS : vfs .NewMem (),
700
+ FS : vfs .NewMem (),
701
+ FileCache : fc ,
700
702
}))
701
703
require .NoError (t , err )
702
704
@@ -710,15 +712,16 @@ func TestIterLeak(t *testing.T) {
710
712
require .NoError (t , iter .Close ())
711
713
require .NoError (t , d .Close ())
712
714
} else {
713
- defer iter .Close ()
714
715
if err := d .Close (); err == nil {
715
716
t .Fatalf ("expected failure, but found success" )
716
717
} else if ! strings .HasPrefix (err .Error (), "leaked iterators:" ) {
717
718
t .Fatalf ("expected leaked iterators, but found %+v" , err )
718
719
} else {
719
720
t .Log (err .Error ())
720
721
}
722
+ iter .Close ()
721
723
}
724
+ fc .Unref ()
722
725
})
723
726
}
724
727
})
@@ -732,13 +735,16 @@ func TestIterLeakSharedCache(t *testing.T) {
732
735
t .Run (fmt .Sprintf ("leak=%t" , leak ), func (t * testing.T ) {
733
736
for _ , flush := range []bool {true , false } {
734
737
t .Run (fmt .Sprintf ("flush=%t" , flush ), func (t * testing.T ) {
738
+ fc := NewFileCache (10 , 100 )
735
739
d1 , err := Open ("" , & Options {
736
- FS : vfs .NewMem (),
740
+ FS : vfs .NewMem (),
741
+ FileCache : fc ,
737
742
})
738
743
require .NoError (t , err )
739
744
740
745
d2 , err := Open ("" , & Options {
741
- FS : vfs .NewMem (),
746
+ FS : vfs .NewMem (),
747
+ FileCache : fc ,
742
748
})
743
749
require .NoError (t , err )
744
750
@@ -789,6 +795,22 @@ func TestIterLeakSharedCache(t *testing.T) {
789
795
}
790
796
}
791
797
798
+ if ! leak {
799
+ fc .Unref ()
800
+ } else if flush {
801
+ require .Panics (t , func () {
802
+ fc .Unref ()
803
+ })
804
+ } else {
805
+ // When we're not flushing and we leak an iterator, Unref might or
806
+ // might not panic, depending on whether there was a file involved.
807
+ func () {
808
+ defer func () {
809
+ recover ()
810
+ }()
811
+ fc .Unref ()
812
+ }()
813
+ }
792
814
})
793
815
}
794
816
})
0 commit comments