Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests leave fingerprint/archive files in ~/.unison #636

Open
gdt opened this issue Feb 13, 2022 · 2 comments
Open

Tests leave fingerprint/archive files in ~/.unison #636

gdt opened this issue Feb 13, 2022 · 2 comments
Labels
build issue in unison build system defect unison fails to meet its specification (but doesn't crash; see also "crash") effort-medium issue is likely resolvable with <= 20h of effort impact-low low importance

Comments

@gdt
Copy link
Collaborator

gdt commented Feb 13, 2022

When running make test, the tests run, which is great, but this results in ar/fp files for the test roots remaining in the user's ~/.unison directory. This behavior is likely to trigger an error in pkgsrc, which creates a fake HOME and checks that it is empty after building (but perhaps not after testing, although it should).

The tests should be independent of the user's enviironment both ways, not reading config, and not writing. To fix, some sort of temporary/fake homedir should be created, or some similar workaround.

@gdt gdt added build issue in unison build system defect unison fails to meet its specification (but doesn't crash; see also "crash") effort-medium issue is likely resolvable with <= 20h of effort impact-low low importance labels Feb 13, 2022
@tleedjarv
Copy link
Contributor

tleedjarv commented Feb 14, 2022

I have two proposals for you.

First is to use the UNISON env variable to use a different homedir. This can easily be done in the Makefile. But this still leaves behind the files you mention and the dir itself.

Second is to have self-test mode remove all files behind itself (see patch proposal below - I can open a PR if you'd like). But this still leaves the homedir behind.

The ultimate solution is probably to combine the two above in Makefile, like this:

  1. create a temp dir somewhere
  2. set UNISON to point to that dir
  3. run the self-tests
  4. drop the temp dir

(One might ask - why not do this sequence without the second proposal above? Well, because running self-tests is possible without a Makefile as well.)

A PR would be appreciated if someone can write this up in the Makefile in a portable way.

A patch to implement the second proposal above:

Edit: This patch is slightly wrong, it does not clean up when a test fails. I'm keeping it as it is here and fix it if there is a desire to get a PR.

diff --git a/src/test.ml b/src/test.ml
index 60ccd052..82df092c 100644
--- a/src/test.ml
+++ b/src/test.ml
@@ -555,6 +555,9 @@ let test() =
     *)
   end;
 
+  Util.msg "Cleaning up...\n";
+  Lwt_unix.run (Update.removeAllArchiveFiles ());
+
   if !failures = 0 then
     Util.msg "Success :-)\n"
   else
diff --git a/src/update.ml b/src/update.ml
index 4fa5ccee..c7cc0616 100644
--- a/src/update.ml
+++ b/src/update.ml
@@ -612,6 +612,14 @@ let removeArchiveLocal ((fspath: Fspath.t), (v: archiveVersion)): unit Lwt.t =
 let removeArchiveOnRoot: Common.root -> archiveVersion -> unit Lwt.t =
   Remote.registerRootCmd "removeArchive" marchiveVersion Umarshal.unit removeArchiveLocal
 
+let removeAllArchiveFiles () =
+  Globals.allRootsIter (fun r ->
+    removeArchiveOnRoot r FPCache >>= fun () ->
+    removeArchiveOnRoot r ScratchArch >>= fun () ->
+    removeArchiveOnRoot r NewArch >>= fun () ->
+    removeArchiveOnRoot r MainArch >>= fun () ->
+    removeArchiveOnRoot r Lock)
+
 (* [commitArchive (fspath, ())] commits the archive for [fspath] by changing
    the filenames from ScratchArch-ones to a NewArch-ones *)
 let commitArchiveLocal ((fspath: Fspath.t), ())
diff --git a/src/update.mli b/src/update.mli
index 7451dd2e..a8f53bb8 100644
--- a/src/update.mli
+++ b/src/update.mli
@@ -99,3 +99,7 @@ val setStasherFun : (Fspath.t -> Path.local -> unit) -> unit
    presentation of the current fspath with the list of names/fspaths of
    all the roots and the current archive format *)
 val archiveHash : Fspath.t -> string
+
+(* Remove all permanent and temporary archive and cache files for current
+   roots. Useful when running self-tests. *)
+val removeAllArchiveFiles : unit -> unit Lwt.t

@gdt
Copy link
Collaborator Author

gdt commented Feb 27, 2022

Let's see where we are after the Makefile cleanup and BUILD.md conversion. It may be that we document that tests run via "make check" -- perhaps after making it so -- in which case ad hoc running of tests doing random things is not really a bug.
But, I'm inclined to have tests clean up after themselves anyway, eventually. Still, I lean to sequencing things for minimum total work.

It also might be that we move at least slightly in the direction of out--of-tree builds (mkdir build; cd build && ../configure, not that unison is like that) and tests could be like that. I am not really bothered by droppings in a build tree; it's the stuff in the real unison dir that is an issue. It's also not a major issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build issue in unison build system defect unison fails to meet its specification (but doesn't crash; see also "crash") effort-medium issue is likely resolvable with <= 20h of effort impact-low low importance
Projects
None yet
Development

No branches or pull requests

2 participants