From a6db102cd2ee02f45ced163b2ba73049fd73f0ca Mon Sep 17 00:00:00 2001 From: AR-May <67507805+AR-May@users.noreply.github.com> Date: Tue, 20 Jul 2021 18:04:35 +0200 Subject: [PATCH] Remove extra lock in ProjectRootElementCache.Get for unit tests. --- .../Evaluation/ProjectRootElementCache.cs | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/Build/Evaluation/ProjectRootElementCache.cs b/src/Build/Evaluation/ProjectRootElementCache.cs index 921a5b39f14..bf519b82224 100644 --- a/src/Build/Evaluation/ProjectRootElementCache.cs +++ b/src/Build/Evaluation/ProjectRootElementCache.cs @@ -157,26 +157,23 @@ private bool IsInvalidEntry(string projectFile, ProjectRootElement projectRootEl } else if (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("MSBUILDCACHECHECKFILECONTENT"))) { - lock (_locker) + // QA tests run too fast for the timestamp check to work. This environment variable is for their + // use: it checks the file content as well as the timestamp. That's better than completely disabling + // the cache as we get test coverage of the rest of the cache code. + XmlDocument document = new XmlDocument(); + document.PreserveWhitespace = projectRootElement.XmlDocument.PreserveWhitespace; + + using (var xtr = XmlReaderExtension.Create(projectRootElement.FullPath, projectRootElement.ProjectRootElementCache.LoadProjectsReadOnly)) + { + document.Load(xtr.Reader); + } + + string diskContent = document.OuterXml; + string cacheContent = projectRootElement.XmlDocument.OuterXml; + + if (diskContent != cacheContent) { - // QA tests run too fast for the timestamp check to work. This environment variable is for their - // use: it checks the file content as well as the timestamp. That's better than completely disabling - // the cache as we get test coverage of the rest of the cache code. - XmlDocument document = new XmlDocument(); - document.PreserveWhitespace = projectRootElement.XmlDocument.PreserveWhitespace; - - using (var xtr = XmlReaderExtension.Create(projectRootElement.FullPath, projectRootElement.ProjectRootElementCache.LoadProjectsReadOnly)) - { - document.Load(xtr.Reader); - } - - string diskContent = document.OuterXml; - string cacheContent = projectRootElement.XmlDocument.OuterXml; - - if (diskContent != cacheContent) - { - return true; - } + return true; } } }