tests: fix a few fd leaks
We relied on the finalizer to close a few fds. For some reason, this did not cause problems on Linux, but on MacOS, it causes unmount failures: umount(/private/tmp/gocryptfs-test-parent/194654785/default-plain): Resource busy -- try 'diskutil unmount'
This commit is contained in:
parent
6c172dcb02
commit
3064d72b97
@ -45,7 +45,7 @@ func TestDirIVRace(t *testing.T) {
|
|||||||
for {
|
for {
|
||||||
// Keep dir2 in the diriv cache
|
// Keep dir2 in the diriv cache
|
||||||
fd, err2 := os.Open(file2)
|
fd, err2 := os.Open(file2)
|
||||||
if err2 != nil {
|
if err2 == nil {
|
||||||
fd.Close()
|
fd.Close()
|
||||||
}
|
}
|
||||||
if stop {
|
if stop {
|
||||||
|
@ -51,6 +51,7 @@ func TestOpenTruncateRead(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer writeFd.Close()
|
||||||
abc := []byte("abc")
|
abc := []byte("abc")
|
||||||
_, err = writeFd.WriteAt(abc, 0)
|
_, err = writeFd.WriteAt(abc, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -61,6 +62,7 @@ func TestOpenTruncateRead(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer readFd.Close()
|
||||||
content := make([]byte, 3)
|
content := make([]byte, 3)
|
||||||
_, err = readFd.ReadAt(content, 0)
|
_, err = readFd.ReadAt(content, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -405,10 +405,12 @@ func TestRmwRace(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("file create failed")
|
t.Fatalf("file create failed")
|
||||||
}
|
}
|
||||||
|
defer f1.Close()
|
||||||
f2, err := os.Create(fn)
|
f2, err := os.Create(fn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("file create failed")
|
t.Fatalf("file create failed")
|
||||||
}
|
}
|
||||||
|
defer f2.Close()
|
||||||
|
|
||||||
oldBlock := bytes.Repeat([]byte("o"), 4096)
|
oldBlock := bytes.Repeat([]byte("o"), 4096)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user