From 26416f6d20044d693ddfb57d719ee5183c065fc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 24 Dec 2015 17:51:19 +0000 Subject: [PATCH] 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. --- tests/threads/refdb.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/threads/refdb.c b/tests/threads/refdb.c index 9b1b37592..0c5cd2be6 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); } }