From 4b08c3a5c371a28cff2a0c451a9ac7c89cd365dc Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 9 Oct 2017 18:20:07 +1100 Subject: [PATCH] Reset PluginManager on each tests, no reason not to, this should resolve the issue --- src/Umbraco.Core/PluginManager.cs | 35 +++++++------- .../TestHelpers/BaseUmbracoApplicationTest.cs | 48 +++++++------------ 2 files changed, 33 insertions(+), 50 deletions(-) diff --git a/src/Umbraco.Core/PluginManager.cs b/src/Umbraco.Core/PluginManager.cs index aafbc92b8b..aa318de287 100644 --- a/src/Umbraco.Core/PluginManager.cs +++ b/src/Umbraco.Core/PluginManager.cs @@ -76,22 +76,22 @@ namespace Umbraco.Core RequiresRescanning = (CachedAssembliesHash != CurrentAssembliesHash) || CachedAssembliesHash == string.Empty; //if they have changed, we need to write the new file if (RequiresRescanning) - { - // if the hash has changed, clear out the persisted list no matter what, this will force - // rescanning of all plugin types including lazy ones. - // http://issues.umbraco.org/issue/U4-4789 - if(File.Exists(_pluginListFilePath.Value)) + { + // if the hash has changed, clear out the persisted list no matter what, this will force + // rescanning of all plugin types including lazy ones. + // http://issues.umbraco.org/issue/U4-4789 + if(File.Exists(_pluginListFilePath.Value)) File.Delete(_pluginListFilePath.Value); WriteCachePluginsHash(); } } else - { - // if the hash has changed, clear out the persisted list no matter what, this will force - // rescanning of all plugin types including lazy ones. + { + // if the hash has changed, clear out the persisted list no matter what, this will force + // rescanning of all plugin types including lazy ones. // http://issues.umbraco.org/issue/U4-4789 - if (File.Exists(_pluginListFilePath.Value)) + if (File.Exists(_pluginListFilePath.Value)) File.Delete(_pluginListFilePath.Value); // always set to true if we're not detecting (generally only for testing) @@ -270,7 +270,7 @@ namespace Umbraco.Core } } } - return generator.GenerateHash(); + return generator.GenerateHash(); } } } @@ -310,7 +310,7 @@ namespace Umbraco.Core uniqInfos.Add(fileOrFolder.FullName); generator.AddFileSystemItem(fileOrFolder); } - return generator.GenerateHash(); + return generator.GenerateHash(); } } } @@ -343,7 +343,7 @@ namespace Umbraco.Core { return ReadCache(); } - catch + catch (Exception ex) { try { @@ -440,7 +440,7 @@ namespace Umbraco.Core pluginListFilePath = Path.Combine(tempFolder, "umbraco-plugins." + NetworkHelper.FileSafeMachineName + ".list"); break; } - + //ensure the folder exists var folder = Path.GetDirectoryName(pluginListFilePath); if (folder == null) @@ -503,8 +503,7 @@ namespace Umbraco.Core internal void UpdateCache() { - // note - // at the moment we write the cache to disk every time we update it. ideally we defer the writing + // TODO: at the moment we write the cache to disk every time we update it. ideally we defer the writing // since all the updates are going to happen in a row when Umbraco starts. that being said, the // file is small enough, so it is not a priority. WriteCache(); @@ -517,13 +516,13 @@ namespace Umbraco.Core while (true) { try - { + { return new FileStream(path, fileMode, fileAccess, fileShare); } - catch + catch (Exception ex) { if (--attempts == 0) - throw; + throw; LogHelper.Debug(string.Format("Attempted to get filestream for file {0} failed, {1} attempts left, pausing for {2} milliseconds", path, attempts, pauseMilliseconds)); Thread.Sleep(pauseMilliseconds); diff --git a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs index 49895ed453..6444638928 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs @@ -118,25 +118,12 @@ namespace Umbraco.Tests.TestHelpers }); } - /// - /// By default this returns false which means the plugin manager will not be reset so it doesn't need to re-scan - /// all of the assemblies. Inheritors can override this if plugin manager resetting is required, generally needs - /// to be set to true if the SetupPluginManager has been overridden. - /// - protected virtual bool PluginManagerResetRequired - { - get { return false; } - } - /// /// Inheritors can resset the plugin manager if they choose to on teardown /// protected virtual void ResetPluginManager() { - if (PluginManagerResetRequired) - { - PluginManager.Current = null; - } + PluginManager.Current = null; } protected virtual CacheHelper CreateCacheHelper() @@ -185,26 +172,23 @@ namespace Umbraco.Tests.TestHelpers /// protected virtual void SetupPluginManager() { - if (PluginManager.Current == null || PluginManagerResetRequired) + PluginManager.Current = new PluginManager( + new ActivatorServiceProvider(), + CacheHelper.RuntimeCache, ProfilingLogger, false) { - PluginManager.Current = new PluginManager( - new ActivatorServiceProvider(), - CacheHelper.RuntimeCache, ProfilingLogger, false) + AssembliesToScan = new[] { - AssembliesToScan = new[] - { - Assembly.Load("Umbraco.Core"), - Assembly.Load("umbraco"), - Assembly.Load("Umbraco.Tests"), - Assembly.Load("businesslogic"), - Assembly.Load("cms"), - Assembly.Load("controls"), - Assembly.Load("umbraco.editorControls"), - Assembly.Load("umbraco.MacroEngines"), - Assembly.Load("umbraco.providers"), - } - }; - } + Assembly.Load("Umbraco.Core"), + Assembly.Load("umbraco"), + Assembly.Load("Umbraco.Tests"), + Assembly.Load("businesslogic"), + Assembly.Load("cms"), + Assembly.Load("controls"), + Assembly.Load("umbraco.editorControls"), + Assembly.Load("umbraco.MacroEngines"), + Assembly.Load("umbraco.providers"), + } + }; } ///