tests/test-filecache.py
changeset 29995 57830bd0e787
parent 28803 76c091f9711e
child 30332 318a24b52eeb
equal deleted inserted replaced
29994:0c40e64d6154 29995:57830bd0e787
   177     f.write('b')
   177     f.write('b')
   178     f.close()
   178     f.close()
   179     print("* file y created")
   179     print("* file y created")
   180     print(repo.cached)
   180     print(repo.cached)
   181 
   181 
       
   182 def antiambiguity():
       
   183     filename = 'ambigcheck'
       
   184 
       
   185     # try some times, because reproduction of ambiguity depends on
       
   186     # "filesystem time"
       
   187     for i in xrange(5):
       
   188         fp = open(filename, 'w')
       
   189         fp.write('FOO')
       
   190         fp.close()
       
   191 
       
   192         oldstat = os.stat(filename)
       
   193         if oldstat.st_ctime != oldstat.st_mtime:
       
   194             # subsequent changing never causes ambiguity
       
   195             continue
       
   196 
       
   197         repetition = 3
       
   198 
       
   199         # repeat changing via checkambigatclosing, to examine whether
       
   200         # st_mtime is advanced multiple times as expecetd
       
   201         for i in xrange(repetition):
       
   202             # explicit closing
       
   203             fp = scmutil.checkambigatclosing(open(filename, 'a'))
       
   204             fp.write('FOO')
       
   205             fp.close()
       
   206 
       
   207             # implicit closing by "with" statement
       
   208             with scmutil.checkambigatclosing(open(filename, 'a')) as fp:
       
   209                 fp.write('BAR')
       
   210 
       
   211         newstat = os.stat(filename)
       
   212         if oldstat.st_ctime != newstat.st_ctime:
       
   213             # timestamp ambiguity was naturally avoided while repetition
       
   214             continue
       
   215 
       
   216         # st_mtime should be advanced "repetition * 2" times, because
       
   217         # all changes occured at same time (in sec)
       
   218         expected = (oldstat.st_mtime + repetition * 2) & 0x7fffffff
       
   219         if newstat.st_mtime != expected:
       
   220             print("'newstat.st_mtime %s is not %s (as %s + %s * 2)" %
       
   221                   (newstat.st_mtime, expected, oldstat.st_mtime, repetition))
       
   222 
       
   223         # no more examination is needed regardless of result
       
   224         break
       
   225     else:
       
   226         # This platform seems too slow to examine anti-ambiguity
       
   227         # of file timestamp (or test happened to be executed at
       
   228         # bad timing). Exit silently in this case, because running
       
   229         # on other faster platforms can detect problems
       
   230         pass
       
   231 
   182 print('basic:')
   232 print('basic:')
   183 print()
   233 print()
   184 basic(fakerepo())
   234 basic(fakerepo())
   185 print()
   235 print()
   186 print('fakeuncacheable:')
   236 print('fakeuncacheable:')
   189 test_filecache_synced()
   239 test_filecache_synced()
   190 print()
   240 print()
   191 print('setbeforeget:')
   241 print('setbeforeget:')
   192 print()
   242 print()
   193 setbeforeget(fakerepo())
   243 setbeforeget(fakerepo())
       
   244 print()
       
   245 print('antiambiguity:')
       
   246 print()
       
   247 antiambiguity()