summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-06-02 16:46:47 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2014-06-02 16:46:47 +0200
commit4ee2543c5ac1e7ed2f849968a7396f04d83fee54 (patch)
tree0a0aa0f79c21cb490de62396131b24f816945c43
parent2f6f6ebc9937220302875de96ce129919296670a (diff)
downloadlibgit2-4ee2543c5ac1e7ed2f849968a7396f04d83fee54.tar.gz
refs: failing test for concurrent ref access
If we remove a reference while we're iterating through the packed refs, the position in the iterator will be off.
-rw-r--r--tests/refs/iterator.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/refs/iterator.c b/tests/refs/iterator.c
index a29b0cf8b..c77451309 100644
--- a/tests/refs/iterator.c
+++ b/tests/refs/iterator.c
@@ -186,3 +186,36 @@ void test_refs_iterator__foreach_name_can_cancel(void)
-333);
cl_assert_equal_i(0, cancel_after);
}
+
+void test_refs_iterator__concurrent_delete(void)
+{
+ git_reference_iterator *iter;
+ size_t full_count = 0, concurrent_count = 0;
+ const char *name;
+ int error;
+
+ git_repository_free(repo);
+ repo = cl_git_sandbox_init("testrepo");
+
+ cl_git_pass(git_reference_iterator_new(&iter, repo));
+ while ((error = git_reference_next_name(&name, iter)) == 0) {
+ full_count++;
+ }
+
+ git_reference_iterator_free(iter);
+ cl_assert_equal_i(GIT_ITEROVER, error);
+
+ cl_git_pass(git_reference_iterator_new(&iter, repo));
+ while ((error = git_reference_next_name(&name, iter)) == 0) {
+ cl_git_pass(git_reference_remove(repo, name));
+ concurrent_count++;
+ }
+
+ git_reference_iterator_free(iter);
+ cl_assert_equal_i(GIT_ITEROVER, error);
+
+ cl_assert_equal_i(full_count, concurrent_count);
+
+ cl_git_sandbox_cleanup();
+ repo = NULL;
+}