Skip to content

Commit 26416f6

Browse files
committed
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 parent 2e09106 commit 26416f6

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

tests/threads/refdb.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static void *iterate_refs(void *arg)
5252

5353
static void *create_refs(void *arg)
5454
{
55-
int i;
55+
int i, error;
5656
struct th_data *data = (struct th_data *) arg;
5757
git_oid head;
5858
char name[128];
@@ -70,7 +70,9 @@ static void *create_refs(void *arg)
7070
if (i == 5) {
7171
git_refdb *refdb;
7272
cl_git_pass(git_repository_refdb(&refdb, repo));
73-
cl_git_pass(git_refdb_compress(refdb));
73+
do {
74+
error = git_refdb_compress(refdb);
75+
} while (error == GIT_ELOCKED);
7476
git_refdb_free(refdb);
7577
}
7678
}
@@ -86,7 +88,7 @@ static void *create_refs(void *arg)
8688

8789
static void *delete_refs(void *arg)
8890
{
89-
int i;
91+
int i, error;
9092
struct th_data *data = (struct th_data *) arg;
9193
git_reference *ref;
9294
char name[128];
@@ -99,14 +101,20 @@ static void *delete_refs(void *arg)
99101
name, sizeof(name), "refs/heads/thread-%03d-%02d", (data->id) & ~0x3, i);
100102

101103
if (!git_reference_lookup(&ref, repo, name)) {
102-
cl_git_pass(git_reference_delete(ref));
104+
do {
105+
error = git_reference_delete(ref);
106+
} while (error == GIT_ELOCKED);
107+
cl_git_pass(error);
103108
git_reference_free(ref);
104109
}
105110

106111
if (i == 5) {
107112
git_refdb *refdb;
108113
cl_git_pass(git_repository_refdb(&refdb, repo));
109-
cl_git_pass(git_refdb_compress(refdb));
114+
do {
115+
error = git_refdb_compress(refdb);
116+
} while (error == GIT_ELOCKED);
117+
cl_git_pass(error);
110118
git_refdb_free(refdb);
111119
}
112120
}

0 commit comments

Comments
 (0)