tests: add TestXfs124
This test reproduces the problem xfstests generic/124 uncovered. The warning itself is harmless, but we should either (1) add locking so that this cannot happen anymore or (2) drop the warning. Currently fails: $ go test -v === RUN Test1980Tar --- PASS: Test1980Tar (0.00s) === RUN TestCtlSock --- PASS: TestCtlSock (0.10s) === RUN TestOpenTruncateRead --- PASS: TestOpenTruncateRead (0.00s) === RUN TestWORead --- PASS: TestWORead (0.00s) === RUN TestXfs124 cipherSize 18 == header size: interrupted write? -wpanic turns this warning into a panic: cipherSize 18 == header size: interrupted write?
This commit is contained in:
parent
9ab11aa4d7
commit
9768376bd1
@ -3,8 +3,11 @@ package defaults
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"sync"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
@ -117,7 +120,7 @@ func TestOpenTruncateRead(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestWORead tries to read from a write-only file.
|
||||
// TestWORead tries to read from a write-only FD.
|
||||
func TestWORead(t *testing.T) {
|
||||
fn := test_helpers.DefaultPlainDir + "/TestWORead"
|
||||
fd, err := os.OpenFile(fn, os.O_CREATE|os.O_WRONLY, 0600)
|
||||
@ -131,3 +134,62 @@ func TestWORead(t *testing.T) {
|
||||
t.Error("Reading from write-only file should fail, but did not")
|
||||
}
|
||||
}
|
||||
|
||||
// xfstests generic/124 triggers this warning:
|
||||
// cipherSize 18 == header size: interrupted write?
|
||||
// This test reproduces the problem.
|
||||
func TestXfs124(t *testing.T) {
|
||||
// GOMAXPROCS=8 and N=5000 seem to reliably trigger the problem. With N=1000,
|
||||
// the test passes sometimes.
|
||||
runtime.GOMAXPROCS(8)
|
||||
N := 5000
|
||||
|
||||
fn := test_helpers.DefaultPlainDir + "/TestXfs124"
|
||||
fd, err := os.Create(fn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer fd.Close()
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
|
||||
go func() {
|
||||
buf := make([]byte, 10)
|
||||
var err2 error
|
||||
for i := 0; i < N; i++ {
|
||||
err2 = fd.Truncate(0)
|
||||
if err2 != nil {
|
||||
panic(err2)
|
||||
}
|
||||
_, err2 = fd.WriteAt(buf, 0)
|
||||
if err2 != nil {
|
||||
panic(err2)
|
||||
}
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
fd2, err := os.Open(fn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer fd2.Close()
|
||||
|
||||
go func() {
|
||||
buf := make([]byte, 10)
|
||||
var err3 error
|
||||
for i := 0; i < N; i++ {
|
||||
_, err3 = fd2.ReadAt(buf, 0)
|
||||
if err3 == io.EOF {
|
||||
continue
|
||||
}
|
||||
if err3 != nil {
|
||||
panic(err3)
|
||||
}
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user