tests: test a variety of cache invariants stable
authorMatt Mackall <mpm@selenic.com>
Thu, 28 Apr 2016 16:38:15 -0500
branchstable
changeset 29041 b962ae0a0a05
parent 29040 a4dc5fe7bf54
child 29042 693b856a4d45
tests: test a variety of cache invariants We've historically had a problem maintaining the expected invariants on our caches, especially when introducing new caches. This tests documents the invariants and exercises them across most of our existing cache files.
tests/test-cache-abuse.t
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-cache-abuse.t	Thu Apr 28 16:38:15 2016 -0500
@@ -0,0 +1,100 @@
+Enable obsolete markers
+
+  $ cat >> $HGRCPATH << EOF
+  > [experimental]
+  > evolution=createmarkers
+  > [phases]
+  > publish=False
+  > EOF
+
+Build a repo with some cacheable bits:
+
+  $ hg init a
+  $ cd a
+
+  $ echo a > a
+  $ hg ci -qAm0
+  $ hg tag t1
+  $ hg book -i bk1
+
+  $ hg branch -q b2
+  $ hg ci -Am1
+  $ hg tag t2
+
+  $ echo dumb > dumb
+  $ hg ci -qAmdumb
+  $ hg debugobsolete b1174d11b69e63cb0c5726621a43c859f0858d7f
+
+  $ hg phase -pr t1
+  $ hg phase -fsr t2
+
+Make a helper function to check cache damage invariants:
+
+- command output shouldn't change
+- cache should be present after first use
+- corruption/repair should be silent (no exceptions or warnings)
+- cache should survive deletion, overwrite, and append
+- unreadable / unwriteable caches should be ignored
+- cache should be rebuilt after corruption
+
+  $ damage() {
+  >  CMD=$1
+  >  CACHE=.hg/cache/$2
+  >  CLEAN=$3
+  >  hg $CMD > before
+  >  test -f $CACHE || echo "not present"
+  >  echo bad > $CACHE
+  >  test -z "$CLEAN" || $CLEAN
+  >  hg $CMD > after
+  >  diff -u before after || echo "*** overwrite corruption"
+  >  echo corruption >> $CACHE
+  >  test -z "$CLEAN" || $CLEAN
+  >  hg $CMD > after
+  >  diff -u before after || echo "*** append corruption"
+  >  rm $CACHE
+  >  mkdir $CACHE
+  >  test -z "$CLEAN" || $CLEAN
+  >  hg $CMD > after
+  >  diff -u before after || echo "*** read-only corruption"
+  >  test -d $CACHE || echo "*** directory clobbered"
+  >  rmdir $CACHE
+  >  test -z "$CLEAN" || $CLEAN
+  >  hg $CMD > after
+  >  diff -u before after || echo "*** missing corruption"
+  >  test -f $CACHE || echo "not rebuilt"
+  > }
+
+Beat up tags caches:
+
+  $ damage "tags --hidden" tags2
+  $ damage tags tags2-visible
+  $ damage "tag -f t3" hgtagsfnodes1
+
+Beat up hidden cache:
+
+  $ damage log hidden
+
+Beat up branch caches:
+
+  $ damage branches branch2-base "rm .hg/cache/branch2-[vs]*"
+  $ damage branches branch2-served "rm .hg/cache/branch2-[bv]*"
+  $ damage branches branch2-visible
+  $ damage "log -r branch(.)" rbc-names-v1
+  $ damage "log -r branch(default)" rbc-names-v1
+  $ damage "log -r branch(b2)" rbc-revs-v1
+
+We currently can't detect an rbc cache with unknown names:
+
+  $ damage "log -qr branch(b2)" rbc-names-v1
+  --- before	* (glob)
+  +++ after	* (glob)
+  @@ -1,8 +0,0 @@
+  -2:5fb7d38b9dc4
+  -3:60b597ffdafa
+  -4:b1174d11b69e
+  -5:6354685872c0
+  -6:5ebc725f1bef
+  -7:7b76eec2f273
+  -8:ef3428d9d644
+  -9:ba7a936bc03c
+  *** append corruption