tests/test-filecache.py
changeset 31251 34d57ddaf9f2
parent 31216 21fa3d3688f3
child 31284 74cbbd5420ba
equal deleted inserted replaced
31250:6d44de27790c 31251:34d57ddaf9f2
    11     extensions,
    11     extensions,
    12     hg,
    12     hg,
    13     scmutil,
    13     scmutil,
    14     ui as uimod,
    14     ui as uimod,
    15     util,
    15     util,
       
    16     vfs as vfsmod,
    16 )
    17 )
    17 
    18 
    18 filecache = scmutil.filecache
    19 filecache = scmutil.filecache
    19 
    20 
    20 class fakerepo(object):
    21 class fakerepo(object):
    71     repo.cached
    72     repo.cached
    72 
    73 
    73     # atomic replace file, size doesn't change
    74     # atomic replace file, size doesn't change
    74     # hopefully st_mtime doesn't change as well so this doesn't use the cache
    75     # hopefully st_mtime doesn't change as well so this doesn't use the cache
    75     # because of inode change
    76     # because of inode change
    76     f = scmutil.vfs('.')('x', 'w', atomictemp=True)
    77     f = vfsmod.vfs('.')('x', 'w', atomictemp=True)
    77     f.write('b')
    78     f.write('b')
    78     f.close()
    79     f.close()
    79 
    80 
    80     repo.invalidate()
    81     repo.invalidate()
    81     print("* file x changed inode")
    82     print("* file x changed inode")
    95     repo.invalidate()
    96     repo.invalidate()
    96     print("* file y changed size")
    97     print("* file y changed size")
    97     # should recreate the object
    98     # should recreate the object
    98     repo.cached
    99     repo.cached
    99 
   100 
   100     f = scmutil.vfs('.')('y', 'w', atomictemp=True)
   101     f = vfsmod.vfs('.')('y', 'w', atomictemp=True)
   101     f.write('B')
   102     f.write('B')
   102     f.close()
   103     f.close()
   103 
   104 
   104     repo.invalidate()
   105     repo.invalidate()
   105     print("* file y changed inode")
   106     print("* file y changed inode")
   106     repo.cached
   107     repo.cached
   107 
   108 
   108     f = scmutil.vfs('.')('x', 'w', atomictemp=True)
   109     f = vfsmod.vfs('.')('x', 'w', atomictemp=True)
   109     f.write('c')
   110     f.write('c')
   110     f.close()
   111     f.close()
   111     f = scmutil.vfs('.')('y', 'w', atomictemp=True)
   112     f = vfsmod.vfs('.')('y', 'w', atomictemp=True)
   112     f.write('C')
   113     f.write('C')
   113     f.close()
   114     f.close()
   114 
   115 
   115     repo.invalidate()
   116     repo.invalidate()
   116     print("* both files changed inode")
   117     print("* both files changed inode")
   198 
   199 
   199         # repeat changing via checkambigatclosing, to examine whether
   200         # repeat changing via checkambigatclosing, to examine whether
   200         # st_mtime is advanced multiple times as expected
   201         # st_mtime is advanced multiple times as expected
   201         for i in xrange(repetition):
   202         for i in xrange(repetition):
   202             # explicit closing
   203             # explicit closing
   203             fp = scmutil.checkambigatclosing(open(filename, 'a'))
   204             fp = vfsmod.checkambigatclosing(open(filename, 'a'))
   204             fp.write('FOO')
   205             fp.write('FOO')
   205             fp.close()
   206             fp.close()
   206 
   207 
   207             # implicit closing by "with" statement
   208             # implicit closing by "with" statement
   208             with scmutil.checkambigatclosing(open(filename, 'a')) as fp:
   209             with vfsmod.checkambigatclosing(open(filename, 'a')) as fp:
   209                 fp.write('BAR')
   210                 fp.write('BAR')
   210 
   211 
   211         newstat = os.stat(filename)
   212         newstat = os.stat(filename)
   212         if oldstat.st_ctime != newstat.st_ctime:
   213         if oldstat.st_ctime != newstat.st_ctime:
   213             # timestamp ambiguity was naturally avoided while repetition
   214             # timestamp ambiguity was naturally avoided while repetition