summaryrefslogtreecommitdiff
path: root/git/test/test_repo.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2015-01-07 20:00:06 +0100
committerSebastian Thiel <byronimo@gmail.com>2015-01-07 20:00:21 +0100
commit36cdfd3209909163549850709d7f12fdf1316434 (patch)
tree4aa624df4eb2b345e594764139fa264a486e437d /git/test/test_repo.py
parentf4a49ff2dddc66bbe25af554caba2351fbf21702 (diff)
downloadgitpython-36cdfd3209909163549850709d7f12fdf1316434.tar.gz
Made improvements to assure test-cases don't leak file handles
At least leakage is considerably reduced. Additionally, a test-case was added which triggers failure if auto-disposal of resources wouldn't work. Fixes #60
Diffstat (limited to 'git/test/test_repo.py')
-rw-r--r--git/test/test_repo.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/git/test/test_repo.py b/git/test/test_repo.py
index eb831ce3..260f7d68 100644
--- a/git/test/test_repo.py
+++ b/git/test/test_repo.py
@@ -656,3 +656,20 @@ class TestRepo(TestBase):
open(git_file_path, 'wb').write(('gitdir: %s\n' % real_path_abs).encode('ascii'))
git_file_repo = Repo(rwrepo.working_tree_dir)
assert os.path.abspath(git_file_repo.git_dir) == real_path_abs
+
+ def test_file_handle_leaks(self):
+ def last_commit(repo, rev, path):
+ commit = next(repo.iter_commits(rev, path, max_count=1))
+ commit.tree[path]
+
+ # This is based on this comment
+ # https://github.com/gitpython-developers/GitPython/issues/60#issuecomment-23558741
+ # And we expect to set max handles to a low value, like 64
+ # You should set ulimit -n X, see .travis.yml
+ # The loops below would easily create 500 handles if these would leak (4 pipes + multiple mapped files)
+ for i in range(64):
+ for repo_type in (GitCmdObjectDB, GitDB):
+ repo = Repo(self.rorepo.working_tree_dir, odbt=repo_type)
+ last_commit(repo, 'master', 'git/test/test_base.py')
+ # end for each repository type
+ # end for each iteration