From 59d8e30b15cdeef4fc565dfd8d2a8ab25b5580e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Tue, 26 Sep 2023 16:43:39 +0100 Subject: [PATCH] fix(runtest): clean up after unit test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `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 --- ocaml/libs/vhd/vhd_format_lwt_test/parse_test.ml | 6 +++++- ocaml/libs/vhd/vhd_format_lwt_test/patterns_lwt.ml | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ocaml/libs/vhd/vhd_format_lwt_test/parse_test.ml b/ocaml/libs/vhd/vhd_format_lwt_test/parse_test.ml index 06214954fe6..2df99af8ecf 100644 --- a/ocaml/libs/vhd/vhd_format_lwt_test/parse_test.ml +++ b/ocaml/libs/vhd/vhd_format_lwt_test/parse_test.ml @@ -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 diff --git a/ocaml/libs/vhd/vhd_format_lwt_test/patterns_lwt.ml b/ocaml/libs/vhd/vhd_format_lwt_test/patterns_lwt.ml index 0b4ad2741e3..ea829fa4c97 100644 --- a/ocaml/libs/vhd/vhd_format_lwt_test/patterns_lwt.ml +++ b/ocaml/libs/vhd/vhd_format_lwt_test/patterns_lwt.ml @@ -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