From 53fb823bcc4d9206a768024026b7146cb4e1e507 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 7 Mar 2016 17:37:17 -0500 Subject: [PATCH] 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. --- tests/index/racy.c | 31 ++++++++++++------------------- 1 file 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); }