Skip to content

Commit

Permalink
fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
SandyXSD committed Apr 11, 2022
1 parent 8f21d45 commit b7789b3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pkg/vfs/vfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,16 @@ func TestInternalFile(t *testing.T) {
if e != 0 {
t.Fatalf("open .stats: %s", e)
}
readControl := func(resp []byte, off uint64) (int, syscall.Errno) {
for {
if n, errno := v.Read(ctx, fe.Inode, resp, off, fh); n == 0 {
time.Sleep(time.Millisecond * 300)
} else {
return n, errno
}
}
}

// rmr
buf = make([]byte, 4+4+8+1+4)
w := utils.FromBuffer(buf)
Expand All @@ -713,7 +723,7 @@ func TestInternalFile(t *testing.T) {
}
var off uint64 = uint64(len(buf))
resp := make([]byte, 1024*10)
if n, e := v.Read(ctx, fe.Inode, resp, off, fh); e != 0 || n != 1 {
if n, e := readControl(resp, off); e != 0 || n != 1 {
t.Fatalf("read result: %s %d", e, n)
} else if resp[0] != byte(syscall.ENOENT) {
t.Fatalf("rmr result: %s", string(buf[:n]))
Expand All @@ -731,7 +741,7 @@ func TestInternalFile(t *testing.T) {
}
off += uint64(len(buf))
buf = make([]byte, 1024*10)
if n, e := v.Read(ctx, fe.Inode, buf, off, fh); e != 0 || n == 0 {
if n, e = readControl(buf, off); e != 0 {
t.Fatalf("read result: %s", e)
} else if !strings.Contains(string(buf[:n]), "dirs:") {
t.Fatalf("info result: %s", string(buf[:n]))
Expand All @@ -756,7 +766,7 @@ func TestInternalFile(t *testing.T) {
}
off += uint64(len(buf))
resp = make([]byte, 1024*10)
if n, e = v.Read(ctx, fe.Inode, resp, off, fh); e != 0 || n != 1 {
if n, e = readControl(resp, off); e != 0 || n != 1 {
t.Fatalf("read result: %s", e)
} else if resp[0] != 0 {
t.Fatalf("fill result: %s", string(buf[:n]))
Expand Down

0 comments on commit b7789b3

Please sign in to comment.