refdb: add retry logic to the threaded tests The logic simply consists of retrying for as long as the library says the data is locked, but it eventually gets through.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
diff --git a/tests/threads/refdb.c b/tests/threads/refdb.c
index 9b1b375..0c5cd2b 100644
--- a/tests/threads/refdb.c
+++ b/tests/threads/refdb.c
@@ -52,7 +52,7 @@ static void *iterate_refs(void *arg)
static void *create_refs(void *arg)
{
- int i;
+ int i, error;
struct th_data *data = (struct th_data *) arg;
git_oid head;
char name[128];
@@ -70,7 +70,9 @@ static void *create_refs(void *arg)
if (i == 5) {
git_refdb *refdb;
cl_git_pass(git_repository_refdb(&refdb, repo));
- cl_git_pass(git_refdb_compress(refdb));
+ do {
+ error = git_refdb_compress(refdb);
+ } while (error == GIT_ELOCKED);
git_refdb_free(refdb);
}
}
@@ -86,7 +88,7 @@ static void *create_refs(void *arg)
static void *delete_refs(void *arg)
{
- int i;
+ int i, error;
struct th_data *data = (struct th_data *) arg;
git_reference *ref;
char name[128];
@@ -99,14 +101,20 @@ static void *delete_refs(void *arg)
name, sizeof(name), "refs/heads/thread-%03d-%02d", (data->id) & ~0x3, i);
if (!git_reference_lookup(&ref, repo, name)) {
- cl_git_pass(git_reference_delete(ref));
+ do {
+ error = git_reference_delete(ref);
+ } while (error == GIT_ELOCKED);
+ cl_git_pass(error);
git_reference_free(ref);
}
if (i == 5) {
git_refdb *refdb;
cl_git_pass(git_repository_refdb(&refdb, repo));
- cl_git_pass(git_refdb_compress(refdb));
+ do {
+ error = git_refdb_compress(refdb);
+ } while (error == GIT_ELOCKED);
+ cl_git_pass(error);
git_refdb_free(refdb);
}
}