Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2016-03-08 01:37:17 +0300
committerEdward Thomson <ethomson@github.com>2016-03-08 08:47:55 +0300
commit53fb823bcc4d9206a768024026b7146cb4e1e507 (patch)
treebc5b9fda54f4e94c0a55e45e318082ae48ced7b4 /tests/index
parent565c419972343c6e34dbf24f3d98bbb34b99d20a (diff)
index::racy: force racy entry
Instead of hoping that we can get a racy entry by going real fast and praying real hard, just create a racy entry.
Diffstat (limited to 'tests/index')
-rw-r--r--tests/index/racy.c31
1 files changed, 12 insertions, 19 deletions
diff --git a/tests/index/racy.c b/tests/index/racy.c
index 68aa46007..1768f5efd 100644
--- a/tests/index/racy.c
+++ b/tests/index/racy.c
@@ -105,8 +105,8 @@ static void setup_race(void)
{
git_buf path = GIT_BUF_INIT;
git_index *index;
- const git_index_entry *entry;
- int i, found_race = 0;
+ git_index_entry *entry;
+ struct stat st;
/* Make sure we do have a timestamp */
cl_git_pass(git_repository_index__weakptr(&index, g_repo));
@@ -114,27 +114,20 @@ static void setup_race(void)
cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "A"));
- /* Make sure writing the file, adding and rewriting happen in the same second */
- for (i = 0; i < 10; i++) {
- struct stat st;
- cl_git_mkfile(path.ptr, "A");
+ cl_git_mkfile(path.ptr, "A");
+ cl_git_pass(git_index_add_bypath(index, "A"));
- cl_git_pass(git_index_add_bypath(index, "A"));
- cl_git_mkfile(path.ptr, "B");
- cl_git_pass(git_index_write(index));
+ cl_git_mkfile(path.ptr, "B");
+ cl_git_pass(git_index_write(index));
- cl_git_mkfile(path.ptr, "");
+ cl_git_mkfile(path.ptr, "");
- cl_git_pass(p_stat(path.ptr, &st));
- cl_assert(entry = git_index_get_bypath(index, "A", 0));
- if (entry->mtime.seconds == (int32_t) st.st_mtime) {
- found_race = 1;
- break;
- }
- }
+ cl_git_pass(p_stat(path.ptr, &st));
+ cl_assert(entry = (git_index_entry *)git_index_get_bypath(index, "A", 0));
- if (!found_race)
- cl_fail("failed to find race after 10 attempts");
+ /* force a race */
+ entry->mtime.seconds = st.st_mtime;
+ entry->mtime.nanoseconds = st.st_mtime_nsec;
git_buf_free(&path);
}