tests/testlib/crash_transaction_late.py
changeset 44638 01b0805534bb
child 48699 21ac6aedd5e5
equal deleted inserted replaced
44637:dd5b47fb0860 44638:01b0805534bb
       
     1 # tiny extension to abort a transaction very late during test
       
     2 #
       
     3 # Copyright 2020 Pierre-Yves David <pierre-yves.david@octobus.net>
       
     4 #
       
     5 # This software may be used and distributed according to the terms of the
       
     6 # GNU General Public License version 2 or any later version.
       
     7 
       
     8 from __future__ import absolute_import
       
     9 
       
    10 from mercurial import (
       
    11     error,
       
    12     transaction,
       
    13 )
       
    14 
       
    15 
       
    16 def abort(fp):
       
    17     raise error.Abort(b"This is a late abort")
       
    18 
       
    19 
       
    20 def reposetup(ui, repo):
       
    21 
       
    22     transaction.postfinalizegenerators.add(b'late-abort')
       
    23 
       
    24     class LateAbortRepo(repo.__class__):
       
    25         def transaction(self, *args, **kwargs):
       
    26             tr = super(LateAbortRepo, self).transaction(*args, **kwargs)
       
    27             tr.addfilegenerator(
       
    28                 b'late-abort', [b'late-abort'], abort, order=9999999
       
    29             )
       
    30             return tr
       
    31 
       
    32     repo.__class__ = LateAbortRepo