1
# (C) 2005 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
from bzrlib.selftest import InTempDir
23
return sha.new(t).hexdigest()
28
# allow it to stabilize
29
start = int(time.time())
30
while int(time.time()) == start:
35
class TestStatCache(InTempDir):
36
"""Functional tests for statcache"""
38
from bzrlib.hashcache import HashCache
44
file('foo', 'wb').write('hello')
48
self.assertEquals(hc.get_sha1('foo'),
49
'aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d')
50
self.assertEquals(hc.miss_count, 1)
51
self.assertEquals(hc.hit_count, 0)
53
# check we hit without re-reading
54
self.assertEquals(hc.get_sha1('foo'),
55
'aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d')
56
self.assertEquals(hc.miss_count, 1)
57
self.assertEquals(hc.hit_count, 1)
59
# check again without re-reading
60
self.assertEquals(hc.get_sha1('foo'),
61
'aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d')
62
self.assertEquals(hc.miss_count, 1)
63
self.assertEquals(hc.hit_count, 2)
65
# write new file and make sure it is seen
66
file('foo', 'wb').write('goodbye')
68
self.assertEquals(hc.get_sha1('foo'),
69
'3c8ec4874488f6090a157b014ce3397ca8e06d4f')
70
self.assertEquals(hc.miss_count, 2)
72
# quickly write new file of same size and make sure it is seen
73
# this may rely on detection of timestamps that are too close
75
file('foo', 'wb').write('g00dbye')
76
self.assertEquals(hc.get_sha1('foo'),
79
# this is not quite guaranteed to be true; we might have
80
# crossed a 1s boundary before
81
self.assertEquals(hc.danger_count, 1)
83
self.assertEquals(hc.get_sha1('subdir'), None)