2014-07-16 01:18:24 -07:00
|
|
|
import shared
|
|
|
|
|
|
|
|
from peru.keyval import KeyVal
|
|
|
|
|
|
|
|
|
rewrite the cache to be asynchronous
We've been seeing "Task X took Y seconds" warnings in our tests for a
long time, especially on Windows. Running git commands synchronously
blocks other tasks from running, like display redrawing. It's bad
practice in an async program.
One of the barriers to async-ifying the cache code earlier was that many
commands relied on having exclusive ownership of the index file while
they were running. For example, 1) read a tree into the index, 2) merge
another tree into some subdirectory, 3) write out the result. If any
other git commands ran in the middle of that, it would screw up the
result. So we need to rewrite every cache function to use its own
temporary index file, if we want them to run in parallel.
The reason I'm finally getting around to this now, is that I'm trying to
reduce the number of git commands that run in a no-op sync. One of the
optimizations I'm going to want to do, is to reuse the index file from
the last sync, so that we don't need a `read-tree` and an `update-index`
just to set us up for `diff-files`. But the plumbing to do that right is
pretty much the same as what we should be doing to run every git command
with its own index anyway. So let's just bite the bullet and do that
now, and then reusing index files will be easy after that.
2015-11-21 15:34:29 -05:00
|
|
|
class KeyValTest(shared.PeruTest):
|
2014-07-16 01:18:24 -07:00
|
|
|
def test_keyval(self):
|
|
|
|
root = shared.create_dir()
|
|
|
|
tmp_dir = shared.create_dir()
|
|
|
|
keyval = KeyVal(root, tmp_dir)
|
|
|
|
key = "mykey"
|
|
|
|
# keyval should be empty
|
|
|
|
self.assertFalse(key in keyval)
|
|
|
|
self.assertSetEqual(set(keyval), set())
|
|
|
|
# set a key
|
|
|
|
keyval[key] = "myval"
|
|
|
|
self.assertEqual(keyval[key], "myval")
|
|
|
|
self.assertTrue(key in keyval)
|
|
|
|
self.assertSetEqual(set(keyval), {key})
|
|
|
|
# overwrite the value
|
|
|
|
keyval[key] = "anotherval"
|
|
|
|
self.assertEqual(keyval[key], "anotherval")
|
|
|
|
# instantiate a second keyval on the same dir, should have same content
|
|
|
|
another_keyval = KeyVal(root, tmp_dir)
|
|
|
|
self.assertTrue(key in another_keyval)
|
|
|
|
self.assertEqual(another_keyval[key], "anotherval")
|
|
|
|
self.assertSetEqual(set(another_keyval), {key})
|
|
|
|
# test deletions
|
|
|
|
del keyval[key]
|
|
|
|
self.assertFalse(key in keyval)
|
|
|
|
self.assertFalse(key in another_keyval)
|