Skip to content

Commit

Permalink
fix(runtest): clean up after unit test
Browse files Browse the repository at this point in the history
`parse_test` didn't clean up when the test finished and it left some files in `/tmp` (about 1.3GB in total).
Because the filenames used by the test are deterministically generated a new test run would find a file created by a previous run and fail.
E.g. the RO test would 'chmod' a file to be read-only, and would thus fail to be 'created' by a subsequent test that attempts to create a VHD by opening and closing it in RW mode.

This doesn't fail on the CI or Koji because they always run the tests in a clean env, but it does fail locally when running the test multiple times.
(Most of the time 'dune cache' will prevent rerunning the test, but not always, e.g. if you've just trimmed the cache because you were low on disk space).

Register an `at_exit` handler that cleans up the files (we cannot clean up at the end of each function because some tests rely on files created by earlier steps).

Signed-off-by: Edwin Török <[email protected]>
  • Loading branch information
edwintorok committed Sep 26, 2023
1 parent 38aa3b0 commit 59d8e30
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion ocaml/libs/vhd/vhd_format_lwt_test/parse_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ let make_new_filename =
fun () ->
let this = !counter in
incr counter ;
disk_name_stem ^ string_of_int this ^ disk_suffix
let name = disk_name_stem ^ string_of_int this ^ disk_suffix in
at_exit (fun () ->
try Unix.unlink name with Unix.Unix_error (_, _, _) -> ()
) ;
name

let fill_sector_with pattern =
let b = Io_page.(to_cstruct (get 1)) in
Expand Down
6 changes: 5 additions & 1 deletion ocaml/libs/vhd/vhd_format_lwt_test/patterns_lwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ let make_new_filename =
fun () ->
let this = !counter in
incr counter ;
disk_name_stem ^ string_of_int this ^ disk_suffix
let name = disk_name_stem ^ string_of_int this ^ disk_suffix in
at_exit (fun () ->
try Unix.unlink name with Unix.Unix_error (_, _, _) -> ()
) ;
name

let _fill_sector_with pattern =
let b = Memory.alloc 512 in
Expand Down

0 comments on commit 59d8e30

Please sign in to comment.