/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_lru_cache.py

  • Committer: John Arbash Meinel
  • Date: 2009-06-12 18:05:15 UTC
  • mto: (4371.4.5 vila-better-heads)
  • mto: This revision was merged to the branch mainline in revision 4449.
  • Revision ID: john@arbash-meinel.com-20090612180515-t0cwbjsnve094oik
Add a failing test for handling nodes that are in the same linear chain.

It fails because the ancestry skipping causes us to miss the fact that the two nodes
are actually directly related. We could check at the beginning, as the 
code used to do, but I think that will be incomplete for the more-than-two
heads cases.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2006, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
132
132
        cache[2] = 26
133
133
        self.assertEqual([(2, 20), (2, 25)], cleanup_called)
134
134
 
135
 
    def test_cleanup_error_maintains_linked_list(self):
136
 
        cleanup_called = []
137
 
        def cleanup_func(key, val):
138
 
            cleanup_called.append((key, val))
139
 
            raise ValueError('failure during cleanup')
140
 
 
141
 
        cache = lru_cache.LRUCache(max_cache=10)
142
 
        for i in xrange(10):
143
 
            cache.add(i, i, cleanup=cleanup_func)
144
 
        for i in xrange(10, 20):
145
 
            self.assertRaises(ValueError,
146
 
                cache.add, i, i, cleanup=cleanup_func)
147
 
 
148
 
        self.assertEqual([(i, i) for i in xrange(10)], cleanup_called)
149
 
 
150
 
        self.assertEqual(range(19, 9, -1), [n.key for n in cache._walk_lru()])
151
 
 
152
 
    def test_cleanup_during_replace_still_replaces(self):
153
 
        cleanup_called = []
154
 
        def cleanup_func(key, val):
155
 
            cleanup_called.append((key, val))
156
 
            raise ValueError('failure during cleanup')
157
 
 
158
 
        cache = lru_cache.LRUCache(max_cache=10)
159
 
        for i in xrange(10):
160
 
            cache.add(i, i, cleanup=cleanup_func)
161
 
        self.assertRaises(ValueError,
162
 
            cache.add, 1, 20, cleanup=cleanup_func)
163
 
        # We also still update the recent access to this node
164
 
        self.assertEqual([1, 9, 8, 7, 6, 5, 4, 3, 2, 0],
165
 
                         [n.key for n in cache._walk_lru()])
166
 
        self.assertEqual(20, cache[1])
167
 
 
168
 
        self.assertEqual([(1, 1)], cleanup_called)
169
 
        self.assertEqual([1, 9, 8, 7, 6, 5, 4, 3, 2, 0],
170
 
                         [n.key for n in cache._walk_lru()])
171
 
 
172
135
    def test_len(self):
173
136
        cache = lru_cache.LRUCache(max_cache=10, after_cleanup_count=10)
174
137