Patchwork D10457: nodemap: test various corruption scenario for the persistent nodemap

login
register
mail settings
Submitter phabricator
Date April 16, 2021, 4:08 p.m.
Message ID <differential-rev-PHID-DREV-5q5msljvw5eh46x5rnzr-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48774/
State Superseded
Headers show

Comments

phabricator - April 16, 2021, 4:08 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Corruption can happens in the wild, either because some of our code is buggy or
  because repository were shared/transfered in a strange manners.
  
  Currently one of the corruption case (not enough data) lead to a crash. We add
  explicit tests for theses cases.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

REVISION DETAIL
  https://phab.mercurial-scm.org/D10457

AFFECTED FILES
  tests/test-persistent-nodemap.t

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-persistent-nodemap.t b/tests/test-persistent-nodemap.t
--- a/tests/test-persistent-nodemap.t
+++ b/tests/test-persistent-nodemap.t
@@ -742,3 +742,60 @@ 
   data-length: 121088
   data-unused: 0
   data-unused: 0.000%
+
+Test various corruption case
+============================
+
+Missing datafile
+----------------
+
+Test behavior with a missing datafile
+
+  $ hg clone --quiet --pull test-repo corruption-test-repo
+  $ ls -1 corruption-test-repo/.hg/store/00changelog*
+  corruption-test-repo/.hg/store/00changelog-*.nd (glob)
+  corruption-test-repo/.hg/store/00changelog.d
+  corruption-test-repo/.hg/store/00changelog.i
+  corruption-test-repo/.hg/store/00changelog.n
+  $ rm corruption-test-repo/.hg/store/00changelog*.nd
+  $ hg log -R corruption-test-repo -r .
+  changeset:   5005:90d5d3ba2fc4
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     a2
+  
+  $ ls -1 corruption-test-repo/.hg/store/00changelog*
+  corruption-test-repo/.hg/store/00changelog.d
+  corruption-test-repo/.hg/store/00changelog.i
+  corruption-test-repo/.hg/store/00changelog.n
+
+Truncated data file
+-------------------
+
+Test behavior with a too short datafile
+
+rebuild the missing data
+  $ hg -R corruption-test-repo debugupdatecache
+  $ ls -1 corruption-test-repo/.hg/store/00changelog*
+  corruption-test-repo/.hg/store/00changelog-*.nd (glob)
+  corruption-test-repo/.hg/store/00changelog.d
+  corruption-test-repo/.hg/store/00changelog.i
+  corruption-test-repo/.hg/store/00changelog.n
+
+truncate the file
+
+  $ datafilepath=`ls corruption-test-repo/.hg/store/00changelog*.nd`
+  $ f -s $datafilepath
+  corruption-test-repo/.hg/store/00changelog-*.nd: size=121088 (glob)
+  $ dd if=$datafilepath bs=1000 count=10 of=$datafilepath-tmp status=none
+  $ mv $datafilepath-tmp $datafilepath
+  $ f -s $datafilepath
+  corruption-test-repo/.hg/store/00changelog-*.nd: size=10000 (glob)
+
+Check that Mercurial reaction to this event
+
+  $ hg -R corruption-test-repo log -r .
+  abort: index 00changelog.i is corrupted
+  [50]
+