tests/test-transaction-safety.t
changeset 47236 1422eef04309
child 47237 864f4ebe6a8d
equal deleted inserted replaced
47235:6b1eae313b2f 47236:1422eef04309
       
     1 Test transaction safety
       
     2 =======================
       
     3 
       
     4 This test basic case to make sure external process do not see transaction
       
     5 content until it is committed.
       
     6 
       
     7 # TODO: also add an external reader accessing revlog files while they are written
       
     8 #       (instead of during transaction finalisation)
       
     9 
       
    10 # TODO: also add stream clone and hardlink clone happening during these transaction.
       
    11 
       
    12 setup
       
    13 -----
       
    14 
       
    15 synchronisation+output script:
       
    16 
       
    17   $ mkdir sync
       
    18   $ mkdir output
       
    19   $ mkdir script
       
    20   $ HG_TEST_FILE_EXT_WAITING=$TESTTMP/sync/ext_waiting
       
    21   $ export HG_TEST_FILE_EXT_WAITING
       
    22   $ HG_TEST_FILE_EXT_UNLOCK=$TESTTMP/sync/ext_unlock
       
    23   $ export HG_TEST_FILE_EXT_UNLOCK
       
    24   $ HG_TEST_FILE_EXT_DONE=$TESTTMP/sync/ext_done
       
    25   $ export HG_TEST_FILE_EXT_DONE
       
    26   $ cat << EOF > script/external.sh
       
    27   > #!/bin/sh
       
    28   > $RUNTESTDIR/testlib/wait-on-file 5 $HG_TEST_FILE_EXT_UNLOCK $HG_TEST_FILE_EXT_WAITING
       
    29   > hg log --rev 'tip' -T 'external: {rev} {desc}\n' > $TESTTMP/output/external.out
       
    30   > touch $HG_TEST_FILE_EXT_DONE
       
    31   > EOF
       
    32   $ chmod +x script/external.sh
       
    33   $ cat << EOF > script/internal.sh
       
    34   > #!/bin/sh
       
    35   > hg log --rev 'tip' -T 'internal: {rev} {desc}\n' > $TESTTMP/output/internal.out
       
    36   > $RUNTESTDIR/testlib/wait-on-file 5 $HG_TEST_FILE_EXT_DONE $HG_TEST_FILE_EXT_UNLOCK
       
    37   > EOF
       
    38   $ chmod +x script/internal.sh
       
    39 
       
    40 
       
    41 Automated commands:
       
    42 
       
    43   $ make_one_commit() {
       
    44   > rm -f $TESTTMP/sync/*
       
    45   > rm -f $TESTTMP/output/*
       
    46   > hg log --rev 'tip' -T 'pre-commit: {rev} {desc}\n'
       
    47   > echo x >> a
       
    48   > $TESTTMP/script/external.sh & hg commit -m "$1"
       
    49   > cat $TESTTMP/output/external.out
       
    50   > cat $TESTTMP/output/internal.out
       
    51   > hg log --rev 'tip' -T 'post-tr:  {rev} {desc}\n'
       
    52   > }
       
    53 
       
    54 
       
    55   $ make_one_pull() {
       
    56   > rm -f $TESTTMP/sync/*
       
    57   > rm -f $TESTTMP/output/*
       
    58   > hg log --rev 'tip' -T 'pre-commit: {rev} {desc}\n'
       
    59   > echo x >> a
       
    60   > $TESTTMP/script/external.sh & hg pull ../other-repo/ --rev "$1" --force --quiet
       
    61   > cat $TESTTMP/output/external.out
       
    62   > cat $TESTTMP/output/internal.out
       
    63   > hg log --rev 'tip' -T 'post-tr:  {rev} {desc}\n'
       
    64   > }
       
    65 
       
    66 prepare a large source to which to pull from:
       
    67 
       
    68 The source is large to unsure we don't use inline more after the pull
       
    69 
       
    70   $ hg init other-repo
       
    71   $ hg -R other-repo debugbuilddag .+500
       
    72 
       
    73 
       
    74 prepare an empty repository where to make test:
       
    75 
       
    76   $ hg init repo
       
    77   $ cd repo
       
    78   $ touch a
       
    79   $ hg add a
       
    80 
       
    81 prepare a small extension to controll inline size
       
    82 
       
    83   $ mkdir $TESTTMP/ext
       
    84   $ cat << EOF > $TESTTMP/ext/small_inline.py
       
    85   > from mercurial import revlog
       
    86   > revlog._maxinline = 64 * 100
       
    87   > EOF
       
    88 
       
    89 
       
    90 
       
    91 
       
    92   $ cat << EOF >> $HGRCPATH
       
    93   > [extensions]
       
    94   > small_inline=$TESTTMP/ext/small_inline.py
       
    95   > [hooks]
       
    96   > pretxnclose = $TESTTMP/script/internal.sh
       
    97   > EOF
       
    98 
       
    99 check this is true for the initial commit (inline → inline)
       
   100 -----------------------------------------------------------
       
   101 
       
   102 the repository should still be inline (for relevant format)
       
   103 
       
   104   $ make_one_commit first
       
   105   pre-commit: -1 
       
   106   external: -1 
       
   107   internal: 0 first
       
   108   post-tr:  0 first
       
   109   $ hg debugrevlog -c | grep inline
       
   110   flags  : inline
       
   111 
       
   112 check this is true for extra commit (inline → inline)
       
   113 -----------------------------------------------------
       
   114 
       
   115 the repository should still be inline (for relevant format)
       
   116 
       
   117   $ hg debugrevlog -c | grep inline
       
   118   flags  : inline
       
   119   $ make_one_commit second
       
   120   pre-commit: 0 first
       
   121   external: 0 first
       
   122   internal: 1 second
       
   123   post-tr:  1 second
       
   124   $ hg debugrevlog -c | grep inline
       
   125   flags  : inline
       
   126 
       
   127 check this is true for a small pull (inline → inline)
       
   128 -----------------------------------------------------
       
   129 
       
   130 the repository should still be inline (for relevant format)
       
   131 
       
   132   $ hg debugrevlog -c | grep inline
       
   133   flags  : inline
       
   134   $ make_one_pull 3
       
   135   pre-commit: 1 second
       
   136   warning: repository is unrelated
       
   137   external: 1 second
       
   138   internal: 5 r3
       
   139   post-tr:  5 r3
       
   140   $ hg debugrevlog -c | grep inline
       
   141   flags  : inline
       
   142 
       
   143 Make a large pull (inline → no-inline)
       
   144 ---------------------------------------
       
   145 
       
   146 the repository should no longer be inline (for relevant format)
       
   147 
       
   148   $ hg debugrevlog -c | grep inline
       
   149   flags  : inline
       
   150   $ make_one_pull 400
       
   151   pre-commit: 5 r3
       
   152   external: 5 r3
       
   153   internal: 402 r400
       
   154   post-tr:  402 r400
       
   155   $ hg debugrevlog -c | grep inline
       
   156   [1]
       
   157 
       
   158 check this is true for extra commit (no-inline → no-inline)
       
   159 -----------------------------------------------------------
       
   160 
       
   161 the repository should no longer be inline (for relevant format)
       
   162   $ hg debugrevlog -c | grep inline
       
   163   [1]
       
   164   $ make_one_commit third
       
   165   pre-commit: 402 r400
       
   166   external: 402 r400
       
   167   internal: 403 third
       
   168   post-tr:  403 third
       
   169   $ hg debugrevlog -c | grep inline
       
   170   [1]
       
   171 
       
   172 
       
   173 Make a  pull (not-inline → no-inline)
       
   174 -------------------------------------
       
   175 
       
   176 the repository should no longer be inline (for relevant format)
       
   177 
       
   178   $ hg debugrevlog -c | grep inline
       
   179   [1]
       
   180   $ make_one_pull tip
       
   181   pre-commit: 403 third
       
   182   external: 403 third
       
   183   internal: 503 r500
       
   184   post-tr:  503 r500
       
   185   $ hg debugrevlog -c | grep inline
       
   186   [1]