]> git.michaelhowe.org Git - packages/b/bup.git/commitdiff
rm-between-index-and-save.sh: fix race condition.
authorTim Riemenschneider <git@tim-riemenschneider.de>
Mon, 15 Apr 2013 19:54:18 +0000 (21:54 +0200)
committerRob Browning <rlb@defaultvalue.org>
Thu, 2 May 2013 02:16:04 +0000 (21:16 -0500)
Fix a timing issue that often caused the test to fail -- the (removed)
file "foo" was marked as invalid in the index when it shouldn't have
been because it was modified less than tmax before the index run.

Insert a "bup tick" just before "bup index" so that foo won't be
marked invalid by the second run.

Don't expect the second "bup save" to fail since foo will now be valid
in the index (and hence ignored), even though it is no longer
available.  The removal will be noticed by the next index+save.

When removing directories, the outcome is different: since metadata is
saved per directory, "bup save" notices that the directory is missing
and logs an "errno 2" error, but does not crash, which is what the
tested patch is concerned with.  A third index+save run completes
without error.

This also means that without a "bup tick" before an index run, calls,
"bup save" might exit with non-zero exitcode when files/directories
are removed after bup index, but bup is not guaranteed to notice
missing files.

Signed-off-by: Tim Riemenschneider <git@tim-riemenschneider.de>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
t/test-rm-between-index-and-save.sh

index 1f21ac7a5666dd151fdb9c31d86baccf1204716d..65a1a721941ac04c438a0d0a16b49190f1e3ed84 100755 (executable)
@@ -17,15 +17,30 @@ mkdir "$D"
 bup init
 echo "content" > "$D"/foo
 echo "content" > "$D"/bar
+bup tick
 bup index -ux "$D"
 bup save -n save-fail-missing "$D"
 echo "content" > "$D"/baz
+bup tick
 bup index -ux "$D"
 rm "$D"/foo
-WVFAIL bup save -n save-fail-missing "$D"
+# When "bup tick" is removed above, this may fail (complete with warning),
+# since the ctime/mtime of "foo" might be pushed back:
+WVPASS bup save -n save-fail-missing "$D"
+# when the save-call failed, foo is missing from output, since only
+# then bup notices, that it was removed:
+WVPASSEQ "$(bup ls -a save-fail-missing/latest/$TOP/$D/)" "bar
+baz
+foo"
+# index/save again
+bup tick
+bup index -ux "$D"
+WVPASS bup save -n save-fail-missing "$D"
+# now foo is gone:
 WVPASSEQ "$(bup ls -a save-fail-missing/latest/$TOP/$D/)" "bar
 baz"
 
+
 # TODO: Test for racecondition between reading a file and reading its metadata?
 
 WVSTART "remove dir"
@@ -35,13 +50,26 @@ rm -r "$BUP_DIR"
 bup init
 mkdir "$D"/foo
 mkdir "$D"/bar
+bup tick
 bup index -ux "$D"
 bup save -n save-fail-missing "$D"
 touch "$D"/bar
 mkdir "$D"/baz
+bup tick
 bup index -ux "$D"
 rmdir "$D"/foo
+# with directories, bup notices that foo is missing, so it fails
+# (complete with delayed error)
 WVFAIL bup save -n save-fail-missing "$D"
+# ... so "foo" is absent from "bup ls"
+WVPASSEQ "$(bup ls -a save-fail-missing/latest/$TOP/$D/)" "bar/
+baz/"
+# Index again:
+bup tick
+bup index -ux "$D"
+# no non-zero-exitcode anymore:
+WVPASS bup save -n save-fail-missing "$D"
+# foo is (still...) missing, of course:
 WVPASSEQ "$(bup ls -a save-fail-missing/latest/$TOP/$D/)" "bar/
 baz/"