From 22afe5e341372540357ed2380f125e6b1b9e2913 Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 26 Apr 2021 15:40:46 +1000 Subject: [PATCH] Adds cold boot restart to load test proj --- src/Umbraco.TestData/LoadTestComponent.cs | 35 ++++++++++++++ src/Umbraco.TestData/LoadTestComposer.cs | 29 +++++++++++ src/Umbraco.TestData/LoadTestController.cs | 51 +++++--------------- src/Umbraco.TestData/Umbraco.TestData.csproj | 2 + 4 files changed, 77 insertions(+), 40 deletions(-) create mode 100644 src/Umbraco.TestData/LoadTestComponent.cs create mode 100644 src/Umbraco.TestData/LoadTestComposer.cs diff --git a/src/Umbraco.TestData/LoadTestComponent.cs b/src/Umbraco.TestData/LoadTestComponent.cs new file mode 100644 index 0000000000..97c006520d --- /dev/null +++ b/src/Umbraco.TestData/LoadTestComponent.cs @@ -0,0 +1,35 @@ +using System.Web.Mvc; +using System.Web.Routing; +using Umbraco.Core.Composing; +using System.Configuration; + +// see https://github.com/Shazwazza/UmbracoScripts/tree/master/src/LoadTesting + +namespace Umbraco.TestData +{ + public class LoadTestComponent : IComponent + { + public void Initialize() + { + if (ConfigurationManager.AppSettings["Umbraco.TestData.Enabled"] != "true") + return; + + + + RouteTable.Routes.MapRoute( + name: "LoadTest", + url: "LoadTest/{action}", + defaults: new + { + controller = "LoadTest", + action = "Index" + }, + namespaces: new[] { "Umbraco.TestData" } + ); + } + + public void Terminate() + { + } + } +} diff --git a/src/Umbraco.TestData/LoadTestComposer.cs b/src/Umbraco.TestData/LoadTestComposer.cs new file mode 100644 index 0000000000..2c5e404642 --- /dev/null +++ b/src/Umbraco.TestData/LoadTestComposer.cs @@ -0,0 +1,29 @@ +using Umbraco.Core.Composing; +using System.Configuration; +using Umbraco.Web.PublishedCache.NuCache; + +// see https://github.com/Shazwazza/UmbracoScripts/tree/master/src/LoadTesting + +namespace Umbraco.TestData +{ + public class LoadTestComposer : ComponentComposer, IUserComposer + { + public override void Compose(Composition composition) + { + base.Compose(composition); + + if (ConfigurationManager.AppSettings["Umbraco.TestData.Enabled"] != "true") + return; + + composition.Register(typeof(LoadTestController), Lifetime.Request); + + if (ConfigurationManager.AppSettings["Umbraco.TestData.IgnoreLocalDb"] == "true") + { + composition.Register(factory => new PublishedSnapshotServiceOptions + { + IgnoreLocalDb = true + }); + } + } + } +} diff --git a/src/Umbraco.TestData/LoadTestController.cs b/src/Umbraco.TestData/LoadTestController.cs index 97665dd084..8e1faf56d1 100644 --- a/src/Umbraco.TestData/LoadTestController.cs +++ b/src/Umbraco.TestData/LoadTestController.cs @@ -6,10 +6,9 @@ using Umbraco.Core.Services; using Umbraco.Core.Models; using System.Web; using System.Web.Hosting; -using System.Web.Routing; using System.Diagnostics; -using Umbraco.Core.Composing; -using System.Configuration; +using Umbraco.Core.IO; +using System.IO; // see https://github.com/Shazwazza/UmbracoScripts/tree/master/src/LoadTesting @@ -261,6 +260,15 @@ namespace Umbraco.TestData HttpRuntime.UnloadAppDomain(); } + public ActionResult ColdBootRestart() + { + Directory.Delete(IOHelper.MapPath("~/App_Data/TEMP/DistCache"), true); + + DoRestart(); + + return Content("Cold Boot Restarted."); + } + public ActionResult Restart() { DoRestart(); @@ -331,41 +339,4 @@ namespace Umbraco.TestData return t; } } - - public class TestComponent : IComponent - { - public void Initialize() - { - if (ConfigurationManager.AppSettings["Umbraco.TestData.Enabled"] != "true") - return; - - RouteTable.Routes.MapRoute( - name: "LoadTest", - url: "LoadTest/{action}", - defaults: new - { - controller = "LoadTest", - action = "Index" - }, - namespaces: new[] { "Umbraco.TestData" } - ); - } - - public void Terminate() - { - } - } - - public class TestComposer : ComponentComposer, IUserComposer - { - public override void Compose(Composition composition) - { - base.Compose(composition); - - if (ConfigurationManager.AppSettings["Umbraco.TestData.Enabled"] != "true") - return; - - composition.Register(typeof(LoadTestController), Lifetime.Request); - } - } } diff --git a/src/Umbraco.TestData/Umbraco.TestData.csproj b/src/Umbraco.TestData/Umbraco.TestData.csproj index a3753cc17b..113d209ef4 100644 --- a/src/Umbraco.TestData/Umbraco.TestData.csproj +++ b/src/Umbraco.TestData/Umbraco.TestData.csproj @@ -41,6 +41,8 @@ + +