Commit 7ece906598fff75ea0d0b73b7158c077e6654698

Edward Thomson 2017-04-03T23:07:16

win32: make posix emulation retries configurable POSIX emulation retries should be configurable so that tests can disable them. In particular, maniacally threading tests may end up trying to open locked files and need retries, which will slow continuous integration tests significantly.

diff --git a/src/win32/posix.h b/src/win32/posix.h
index 0ba05a1..64769ec 100644
--- a/src/win32/posix.h
+++ b/src/win32/posix.h
@@ -15,6 +15,7 @@
 #include "dir.h"
 
 extern unsigned long git_win32__createfile_sharemode;
+extern int git_win32__retries;
 
 typedef SOCKET GIT_SOCKET;
 
diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index 874892e..bf13296 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -37,6 +37,7 @@ typedef DWORD(WINAPI *PFGetFinalPathNameByHandleW)(HANDLE, LPWSTR, DWORD, DWORD)
 
 unsigned long git_win32__createfile_sharemode =
  FILE_SHARE_READ | FILE_SHARE_WRITE;
+int git_win32__retries = 10;
 
 GIT_INLINE(void) set_errno(void)
 {
@@ -162,7 +163,7 @@ GIT_INLINE(bool) last_error_retryable(void)
 #define do_with_retries(fn, cleanup) \
 	do {                                                             \
 		int __tries, __ret;                                          \
-		for (__tries = 0; __tries < 10; __tries++) {                 \
+		for (__tries = 0; __tries < git_win32__retries; __tries++) { \
 			if (__tries && (__ret = (cleanup)) != 0)                 \
 				return __ret;                                        \
 			if ((__ret = (fn)) != GIT_RETRY)                         \
diff --git a/tests/threads/diff.c b/tests/threads/diff.c
index c328114..92fd706 100644
--- a/tests/threads/diff.c
+++ b/tests/threads/diff.c
@@ -19,12 +19,20 @@ static git_repository *_repo;
 static git_tree *_a, *_b;
 static git_atomic _counts[4];
 static int _check_counts;
+static int _retries;
 
 #define THREADS 20
 
+void test_threads_diff__initialize(void)
+{
+	_retries = git_win32__retries;
+	git_win32__retries = 1;
+}
+
 void test_threads_diff__cleanup(void)
 {
 	cl_git_sandbox_cleanup();
+	git_win32__retries = _retries;
 }
 
 static void setup_trees(void)