From 07c1513f70fd05fdf5222c7b0dcb98a7579b143e Mon Sep 17 00:00:00 2001
From: Martyn Gigg <martyn.gigg@stfc.ac.uk>
Date: Tue, 27 Mar 2018 12:15:11 +0100
Subject: [PATCH] Create a blank user config file before running tests

Previously we only removed the properties file but some tests
could touch other parts of the user config so remove it all
and create a blank file to ensure the environment is clean.
Refs #22063
---
 buildconfig/Jenkins/buildscript     | 9 ++++++---
 buildconfig/Jenkins/buildscript.bat | 8 ++++++--
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/buildconfig/Jenkins/buildscript b/buildconfig/Jenkins/buildscript
index a5b7c34ce13..a006be8a825 100755
--- a/buildconfig/Jenkins/buildscript
+++ b/buildconfig/Jenkins/buildscript
@@ -300,10 +300,13 @@ fi
 ###############################################################################
 # Run the unit tests
 ###############################################################################
+# Prevent race conditions when creating the user config directory
+userconfig_dir=$HOME/.mantid
+rm -fr $userconfig_dir
+mkdir -p $userconfig_dir
+touch $userconfig_dir/Mantid.user.properties
+
 if [[ ${DO_UNITTESTS} == true ]]; then
-  # Remove any Mantid.user.properties file
-  userprops=~/.mantid/Mantid.user.properties
-  rm -f $userprops
   $CTEST_EXE -j${BUILD_THREADS:?} --schedule-random --output-on-failure
 fi
 
diff --git a/buildconfig/Jenkins/buildscript.bat b/buildconfig/Jenkins/buildscript.bat
index 190353049b9..78194f3dbbf 100755
--- a/buildconfig/Jenkins/buildscript.bat
+++ b/buildconfig/Jenkins/buildscript.bat
@@ -157,10 +157,14 @@ if ERRORLEVEL 1 exit /B %ERRORLEVEL%
 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 :: Run the tests
 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-:: Remove the user properties file just in case anything polluted it
+:: Remove any user configuration and create a blank user properties file
+:: This prevents race conditions when creating the user config directory
 set USERPROPS=bin\%BUILD_CONFIG%\Mantid.user.properties
 del %USERPROPS%
-
+set CONFIGDIR=%APPDATA%\mantidproject\mantid
+rmdir /S /Q %CONFIGDIR%
+mkdir %CONFIGDIR%
+call cmake.exe -E touch %USERPROPS%
 call ctest.exe -C %BUILD_CONFIG% -j%BUILD_THREADS% --schedule-random --output-on-failure
 if ERRORLEVEL 1 exit /B %ERRORLEVEL%
 
-- 
GitLab