Skip to content

Commit

Permalink
tests: Don't leak file descriptors in tests (#729)
Browse files Browse the repository at this point in the history
  • Loading branch information
greatroar authored Jan 7, 2023
1 parent 3dc6c36 commit ded586e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
38 changes: 13 additions & 25 deletions zstd/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ func TestEncoder_EncodeAllEncodeXML(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer f.Close()

dec, err := NewReader(f)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -873,6 +875,8 @@ func TestEncoder_EncodeAllEnwik9(t *testing.T) {
"compress it with 'zstd -15 -T0 enwik9' and place it in " + file)
}
}
defer f.Close()

dec, err := NewReader(f)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -915,6 +919,8 @@ func TestEncoder_EncoderStreamEnwik9(t *testing.T) {
"compress it with 'zstd -15 -T0 enwik9' and place it in " + file)
}
}
defer f.Close()

dec, err := NewReader(f)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -957,6 +963,8 @@ func BenchmarkEncoder_EncodeAllXML(b *testing.B) {
if err != nil {
b.Fatal(err)
}
defer f.Close()

dec, err := NewReader(f)
if err != nil {
b.Fatal(err)
Expand All @@ -983,11 +991,7 @@ func BenchmarkEncoder_EncodeAllXML(b *testing.B) {
}

func BenchmarkEncoder_EncodeAllSimple(b *testing.B) {
f, err := os.Open("testdata/z000028")
if err != nil {
b.Fatal(err)
}
in, err := io.ReadAll(f)
in, err := os.ReadFile("testdata/z000028")
if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -1015,11 +1019,7 @@ func BenchmarkEncoder_EncodeAllSimple(b *testing.B) {
}

func BenchmarkEncoder_EncodeAllSimple4K(b *testing.B) {
f, err := os.Open("testdata/z000028")
if err != nil {
b.Fatal(err)
}
in, err := io.ReadAll(f)
in, err := os.ReadFile("testdata/z000028")
if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -1048,11 +1048,7 @@ func BenchmarkEncoder_EncodeAllSimple4K(b *testing.B) {
}

func BenchmarkEncoder_EncodeAllHTML(b *testing.B) {
f, err := os.Open("../testdata/html.txt")
if err != nil {
b.Fatal(err)
}
in, err := io.ReadAll(f)
in, err := os.ReadFile("../testdata/html.txt")
if err != nil {
b.Fatal(err)
}
Expand All @@ -1072,11 +1068,7 @@ func BenchmarkEncoder_EncodeAllHTML(b *testing.B) {
}

func BenchmarkEncoder_EncodeAllTwain(b *testing.B) {
f, err := os.Open("../testdata/Mark.Twain-Tom.Sawyer.txt")
if err != nil {
b.Fatal(err)
}
in, err := io.ReadAll(f)
in, err := os.ReadFile("../testdata/Mark.Twain-Tom.Sawyer.txt")
if err != nil {
b.Fatal(err)
}
Expand All @@ -1096,11 +1088,7 @@ func BenchmarkEncoder_EncodeAllTwain(b *testing.B) {
}

func BenchmarkEncoder_EncodeAllPi(b *testing.B) {
f, err := os.Open("../testdata/pi.txt")
if err != nil {
b.Fatal(err)
}
in, err := io.ReadAll(f)
in, err := os.ReadFile("../testdata/pi.txt")
if err != nil {
b.Fatal(err)
}
Expand Down
8 changes: 8 additions & 0 deletions zstd/snappy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func TestSnappy_ConvertXML(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer f.Close()

dec, err := NewReader(f)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -163,6 +165,8 @@ func TestSnappy_ConvertEnwik9(t *testing.T) {
"compress it with 'zstd -15 -T0 enwik9' and place it in " + file)
}
}
defer f.Close()

dec, err := NewReader(f)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -211,6 +215,8 @@ func BenchmarkSnappy_ConvertXML(b *testing.B) {
if err != nil {
b.Fatal(err)
}
defer f.Close()

dec, err := NewReader(f)
if err != nil {
b.Fatal(err)
Expand Down Expand Up @@ -254,6 +260,8 @@ func BenchmarkSnappy_Enwik9(b *testing.B) {
b.Skip(err)
return
}
defer f.Close()

dec, err := NewReader(f)
if err != nil {
b.Fatal(err)
Expand Down

0 comments on commit ded586e

Please sign in to comment.