OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import os | 6 import os |
7 import sys | 7 import sys |
8 import unittest | 8 import unittest |
9 | 9 |
10 from caching_file_system import CachingFileSystem | 10 from caching_file_system import CachingFileSystem |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 # All data should be cached. | 285 # All data should be cached. |
286 self.assertTrue(*mock_fs.CheckAndReset()) | 286 self.assertTrue(*mock_fs.CheckAndReset()) |
287 | 287 |
288 # Starting from a different root should still pull cached data. | 288 # Starting from a different root should still pull cached data. |
289 for walkinfo in file_system.Walk('root/dir1/'): | 289 for walkinfo in file_system.Walk('root/dir1/'): |
290 pass | 290 pass |
291 self.assertTrue(*mock_fs.CheckAndReset()) | 291 self.assertTrue(*mock_fs.CheckAndReset()) |
292 # TODO(ahernandez): Test with a new instance CachingFileSystem so a | 292 # TODO(ahernandez): Test with a new instance CachingFileSystem so a |
293 # different object store is utilized. | 293 # different object store is utilized. |
294 | 294 |
| 295 def testVersionedStat(self): |
| 296 test_fs = TestFileSystem({ |
| 297 'bob': { |
| 298 'bob0': 'bob/bob0 contents', |
| 299 'bob1': 'bob/bob1 contents' |
| 300 } |
| 301 }) |
| 302 |
| 303 # Create a versioned FileSystem and verify that multiple CachingFileSystem |
| 304 # instances wrapping it will share the same stat cache. |
| 305 mock_fs = MockFileSystem(test_fs) |
| 306 mock_fs.SetVersion('abcdefg') |
| 307 |
| 308 def run_and_expect_stat_count(paths, stat_count=0): |
| 309 file_system = self._CreateCachingFileSystem(mock_fs, start_empty=True) |
| 310 [file_system.Stat(path) for path in paths] |
| 311 self.assertTrue(*mock_fs.CheckAndReset(stat_count=stat_count)) |
| 312 |
| 313 run_and_expect_stat_count(['bob/', 'bob/bob0', 'bob/bob1'], stat_count=1) |
| 314 run_and_expect_stat_count(['bob/', 'bob/bob0', 'bob/bob1'], stat_count=0) |
| 315 |
295 if __name__ == '__main__': | 316 if __name__ == '__main__': |
296 unittest.main() | 317 unittest.main() |
OLD | NEW |