Skip to content

Commit

Permalink
add test case for MFS repeated truncation failure.
Browse files Browse the repository at this point in the history
tests #4519

License: MIT
Signed-off-by: Steven Allen <[email protected]>
  • Loading branch information
Stebalien committed Dec 22, 2017
1 parent b611613 commit 14c1688
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions mfs/mfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1131,3 +1131,43 @@ func TestTruncateAtSize(t *testing.T) {
}
fd.Truncate(4)
}

func TestTruncateAndWrite(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ds, rt := setupRoot(ctx, t)

dir := rt.GetValue().(*Directory)

nd := dag.NodeWithData(ft.FilePBData(nil, 0))
fi, err := NewFile("test", nd, dir, ds)
if err != nil {
t.Fatal(err)
}

fd, err := fi.Open(Flags{Read: true, Write: true, Sync: true})
defer fd.Close()
if err != nil {
t.Fatal(err)
}
for i := 0; i < 200; i++ {
err = fd.Truncate(0)
if err != nil {
t.Fatal(err)
}
l, err := fd.Write([]byte("test"))
if err != nil {
t.Fatal(err)
}
if l != len("test") {
t.Fatal("incorrect write length")
}
data, err := ioutil.ReadAll(fd)
if err != nil {
t.Fatal(err)
}
if string(data) != "test" {
t.Errorf("read error at read %d, read: %v", i, data)
}
}
}

0 comments on commit 14c1688

Please sign in to comment.