summaryrefslogtreecommitdiff
path: root/gitdb/test/performance
diff options
context:
space:
mode:
Diffstat (limited to 'gitdb/test/performance')
-rw-r--r--gitdb/test/performance/test_pack.py43
-rw-r--r--gitdb/test/performance/test_stream.py18
2 files changed, 32 insertions, 29 deletions
diff --git a/gitdb/test/performance/test_pack.py b/gitdb/test/performance/test_pack.py
index fc8d9d5..b99b91e 100644
--- a/gitdb/test/performance/test_pack.py
+++ b/gitdb/test/performance/test_pack.py
@@ -92,19 +92,20 @@ class TestPackedDBPerformance(TestBigRepoR):
pdb = GitDB(os.path.join(self.gitrepopath, 'objects'))
mdb = MemoryDB()
for c, sha in enumerate(pdb.sha_iter()):
- ostream = pdb.stream(sha)
- # the issue only showed on larger files which are hardly compressible ...
- if ostream.type != str_blob_type:
- continue
- istream = IStream(ostream.type, ostream.size, ostream.stream)
- mdb.store(istream)
- assert istream.binsha == sha, "Failed on object %s" % bin_to_hex(sha).decode('ascii')
- # this can fail ... sometimes, so the packs dataset should be huge
- assert len(mdb.stream(sha).read()) == ostream.size
+ with pdb.stream(sha) as ostream:
+ # the issue only showed on larger files which are hardly compressible ...
+ if ostream.type != str_blob_type:
+ continue
+ istream = IStream(ostream.type, ostream.size, ostream.stream)
+ mdb.store(istream)
+ assert istream.binsha == sha, "Failed on object %s" % bin_to_hex(sha).decode('ascii')
+ # this can fail ... sometimes, so the packs dataset should be huge
+ with mdb.stream(sha) as ost2:
+ assert len(ost2.read()) == ostream.size
- if c and c % 1000 == 0:
- print("Verified %i loose object compression/decompression cycles" % c, file=sys.stderr)
- mdb._cache.clear()
+ if c and c % 1000 == 0:
+ print("Verified %i loose object compression/decompression cycles" % c, file=sys.stderr)
+ mdb._cache.clear()
# end for each sha to copy
@skip_on_travis_ci
@@ -116,14 +117,16 @@ class TestPackedDBPerformance(TestBigRepoR):
count = 0
st = time()
for entity in pdb.entities():
- pack_verify = entity.is_valid_stream
- sha_by_index = entity.index().sha
- for index in xrange(entity.index().size()):
- try:
- assert pack_verify(sha_by_index(index), use_crc=crc)
- count += 1
- except UnsupportedOperation:
- pass
+ with entity:
+ pack_verify = entity.is_valid_stream
+ idx = entity.index()
+ sha_by_index = idx.sha
+ for index in xrange(idx.size()):
+ try:
+ assert pack_verify(sha_by_index(index), use_crc=crc)
+ count += 1
+ except UnsupportedOperation:
+ pass
# END ignore old indices
# END for each index
# END for each entity
diff --git a/gitdb/test/performance/test_stream.py b/gitdb/test/performance/test_stream.py
index 704f4d0..c9b0f15 100644
--- a/gitdb/test/performance/test_stream.py
+++ b/gitdb/test/performance/test_stream.py
@@ -74,9 +74,9 @@ class TestObjDBPerformance(TestBigRepoR):
# reading all at once
st = time()
- ostream = ldb.stream(sha)
- shadata = ostream.read()
- elapsed_readall = time() - st
+ with ldb.stream(sha) as ostream:
+ shadata = ostream.read()
+ elapsed_readall = time() - st
stream.seek(0)
assert shadata == stream.getvalue()
@@ -87,12 +87,12 @@ class TestObjDBPerformance(TestBigRepoR):
cs = 512 * 1000
chunks = list()
st = time()
- ostream = ldb.stream(sha)
- while True:
- data = ostream.read(cs)
- chunks.append(data)
- if len(data) < cs:
- break
+ with ldb.stream(sha) as ostream:
+ while True:
+ data = ostream.read(cs)
+ chunks.append(data)
+ if len(data) < cs:
+ break
# END read in chunks
elapsed_readchunks = time() - st