~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testhashcache.py

  • Committer: Martin Pool
  • Date: 2005-07-08 02:28:58 UTC
  • Revision ID: mbp@sourcefrog.net-20050708022858-f8323aaea09ea4f2
- more hash-cache tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
 
35
35
class TestHashCache(InTempDir):
36
 
    """Functional tests for hashcache"""
 
36
    """Functional tests for statcache"""
37
37
    def runTest(self):
38
38
        from bzrlib.hashcache import HashCache
39
39
        import os
40
40
        import time
41
41
 
42
 
        # make a dummy bzr directory just to hold the cache
43
 
        os.mkdir('.bzr')
44
42
        hc = HashCache('.')
45
43
 
46
44
        file('foo', 'wb').write('hello')
77
75
        file('foo', 'wb').write('g00dbye')
78
76
        self.assertEquals(hc.get_sha1('foo'),
79
77
                          sha1('g00dbye'))
80
 
 
81
 
        file('foo2', 'wb').write('other file')
82
 
        self.assertEquals(hc.get_sha1('foo2'), sha1('other file'))
83
 
 
84
 
        os.remove('foo2')
85
 
        self.assertEquals(hc.get_sha1('foo2'), None)
86
 
 
87
 
        file('foo2', 'wb').write('new content')
88
 
        self.assertEquals(hc.get_sha1('foo2'), sha1('new content'))
 
78
        
 
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)
 
82
        self.assertEquals(len(hc._cache), 0)
89
83
 
90
84
        self.assertEquals(hc.get_sha1('subdir'), None)
91
85
 
92
 
        # it's likely neither are cached at the moment because they 
93
 
        # changed recently, but we can't be sure
94
86
        pause()
95
87
 
96
 
        # should now be safe to cache it if we reread them
97
 
        self.assertEquals(hc.get_sha1('foo'), sha1('g00dbye'))
 
88
        # should now be safe to cache it
 
89
        self.assertEquals(hc.get_sha1('foo'),
 
90
                          sha1('g00dbye'))
98
91
        self.assertEquals(len(hc._cache), 1)
99
 
        self.assertEquals(hc.get_sha1('foo2'), sha1('new content'))
100
 
        self.assertEquals(len(hc._cache), 2)
101
92
 
102
93
        # write out, read back in and check that we don't need to
103
94
        # re-read any files
104
 
        hc.write()
 
95
        hc.write('stat-cache')
105
96
        del hc
106
97
 
107
98
        hc = HashCache('.')
108
 
        hc.read()
109
 
 
110
 
        self.assertEquals(len(hc._cache), 2)
111
 
        self.assertEquals(hc.get_sha1('foo'), sha1('g00dbye'))
112
 
        self.assertEquals(hc.hit_count, 1)
113
 
        self.assertEquals(hc.miss_count, 0)
114
 
        self.assertEquals(hc.get_sha1('foo2'), sha1('new content'))
115
 
 
 
99
        # hc.read('stat-cache')
116
100
        
117
101
 
118
102