Skip to content

Commit

Permalink
Merge pull request #35 from djs55/fix-test
Browse files Browse the repository at this point in the history
lofs fid improvements
  • Loading branch information
djs55 committed Nov 30, 2015
2 parents d5e0217 + 4353f2c commit 361fd59
Show file tree
Hide file tree
Showing 2 changed files with 214 additions and 88 deletions.
64 changes: 63 additions & 1 deletion lib_test/lofs_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ let create_remove_file () =

let create_remove_dir () =
with_client1 (fun _client1 ->
let filemode = Types.FileMode.make ~owner:[`Write] () in
let filemode = Types.FileMode.make ~owner:[`Read; `Write] () in
Client1.mkdir _client1 [] "foo" filemode
>>= function
| Error (`Msg err) -> Alcotest.fail ("client1: mkdir [] foo: " ^ err)
Expand All @@ -177,6 +177,66 @@ let create_remove_dir () =
Lwt.return ()
)

let failed_remove_clunk_fid () =
with_client1 (fun _client1 ->
let filemode = Types.FileMode.make ~owner:[`Read; `Write; `Execute] () in
Client1.mkdir _client1 [] "foo" filemode
>>= function
| Error (`Msg err) -> Alcotest.fail ("client1: mkdir [] foo: " ^ err)
| Ok _ ->
Client1.mkdir _client1 ["foo"] "bar" filemode
>>= function
| Error (`Msg err) -> Alcotest.fail ("client1: mkdir [foo] bar: " ^ err)
| Ok _ ->
Client1.with_fid _client1
(fun fid ->
Client1.walk_from_root _client1 fid ["foo"]
>>= function
| Error (`Msg err) -> Alcotest.fail ("client1: walk_from_root [foo]: " ^ err)
| Ok _ ->
Client1.LowLevel.remove _client1 fid
>>= function
| Ok () -> Alcotest.fail ("client1: remove a non-empty dir should fail")
| Error (`Msg _) ->
(* The fid should have been clunked so I can now re-use it *)
Client1.walk_from_root _client1 fid []
>>= function
| Error (`Msg err) -> Alcotest.fail ("client1: walk_from_root after failed remove: " ^ err)
| Ok _ ->
Lwt.return ()
)
)

let check_directory_boundary_read () =
with_client1 (fun _client1 ->
let filemode = Types.FileMode.make ~owner:[`Read; `Execute] () in
Client1.mkdir _client1 [] "foo" filemode
>>= function
| Error (`Msg err) -> Alcotest.fail ("client1: mkdir [] foo: " ^ err)
| Ok _ ->
Client1.with_fid _client1
(fun fid ->
Client1.walk_from_root _client1 fid ["foo"]
>>= function
| Error (`Msg err) -> Alcotest.fail ("client1: walk_from_root [foo]: " ^ err)
| Ok _ ->
Client1.LowLevel.openfid _client1 fid Types.OpenMode.read_only
>>= function
| Error (`Msg err) ->
Alcotest.fail ("client1: open: " ^ err)
| Ok _ ->
Client1.LowLevel.read _client1 fid 1024L 16l
>>= function
| Error (`Msg err) ->
Alcotest.fail ("client1: read: " ^ err)
| Ok { Response.Read.data } ->
let n = Cstruct.len data in
if n = 0
then Lwt.return ()
else Alcotest.fail ("client1: read non-zero: " ^ (string_of_int n))
)
)

let () = LogServer.print_debug := false
let () = LogClient1.print_debug := false
let () = LogClient2.print_debug := false
Expand All @@ -190,6 +250,8 @@ let test_client = [
lwt_test "check that create rebinds fids" (fun () -> with_server create_rebind_fid);
lwt_test "check that we can remove a file" (fun () -> with_server create_remove_file);
lwt_test "check that we can remove a directory" (fun () -> with_server create_remove_dir);
lwt_test "failed remove should clunk the fid" (fun () -> with_server failed_remove_clunk_fid);
lwt_test "check reading out-of-bounds on a directory doesn't fail badly" (fun () -> with_server check_directory_boundary_read);
]

let tests = [
Expand Down
Loading

0 comments on commit 361fd59

Please sign in to comment.