From f33b946807402c5851cc3905d17f0ed6a32a61e2 Mon Sep 17 00:00:00 2001 From: Mathew Charles Date: Fri, 15 Sep 2017 14:29:43 -0700 Subject: [PATCH] Fix StandBy mode bug --- .../App_Start/WebHostResolver.cs | 28 ++++++++----------- .../Host/StandbyManagerTests.cs | 6 ++-- .../WebHostResolverTests.cs | 11 +++++--- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/WebJobs.Script.WebHost/App_Start/WebHostResolver.cs b/src/WebJobs.Script.WebHost/App_Start/WebHostResolver.cs index 81398c7f94..b5dffe4ac5 100644 --- a/src/WebJobs.Script.WebHost/App_Start/WebHostResolver.cs +++ b/src/WebJobs.Script.WebHost/App_Start/WebHostResolver.cs @@ -124,29 +124,17 @@ private void EnsureInitialized(WebHostSettings settings) { if (_standbyHostManager == null) { - _standbyScriptHostConfig = CreateStandbyScriptHostConfiguration(settings); - StandbyManager.Initialize(_standbyScriptHostConfig); + _standbyScriptHostConfig = CreateScriptHostConfiguration(settings, true); _standbyHostManager = new WebScriptHostManager(_standbyScriptHostConfig, _secretManagerFactory, _eventManager, _settingsManager, settings); _standbyReceiverManager = new WebHookReceiverManager(_standbyHostManager.SecretManager); + InitializeFileSystem(); + StandbyManager.Initialize(_standbyScriptHostConfig); } } } - internal static ScriptHostConfiguration CreateStandbyScriptHostConfiguration(WebHostSettings settings) - { - settings.ScriptPath = Path.Combine(Path.GetTempPath(), "Functions", "Standby"); - - var scriptHostConfig = CreateScriptHostConfiguration(settings); - - scriptHostConfig.FileLoggingMode = FileLoggingMode.Always; - scriptHostConfig.HostConfig.StorageConnectionString = null; - scriptHostConfig.HostConfig.DashboardConnectionString = null; - - return scriptHostConfig; - } - - internal static ScriptHostConfiguration CreateScriptHostConfiguration(WebHostSettings settings) + internal static ScriptHostConfiguration CreateScriptHostConfiguration(WebHostSettings settings, bool inStandbyMode = false) { var scriptHostConfig = new ScriptHostConfiguration { @@ -158,6 +146,14 @@ internal static ScriptHostConfiguration CreateScriptHostConfiguration(WebHostSet LoggerFactoryBuilder = settings.LoggerFactoryBuilder }; + if (inStandbyMode) + { + scriptHostConfig.RootScriptPath = Path.Combine(Path.GetTempPath(), "Functions", "Standby"); + scriptHostConfig.FileLoggingMode = FileLoggingMode.DebugOnly; + scriptHostConfig.HostConfig.StorageConnectionString = null; + scriptHostConfig.HostConfig.DashboardConnectionString = null; + } + scriptHostConfig.HostConfig.HostId = Utility.GetDefaultHostId(_settingsManager, scriptHostConfig); return scriptHostConfig; diff --git a/test/WebJobs.Script.Tests.Integration/Host/StandbyManagerTests.cs b/test/WebJobs.Script.Tests.Integration/Host/StandbyManagerTests.cs index 319ff3a9f3..2a1831a461 100644 --- a/test/WebJobs.Script.Tests.Integration/Host/StandbyManagerTests.cs +++ b/test/WebJobs.Script.Tests.Integration/Host/StandbyManagerTests.cs @@ -116,10 +116,8 @@ public async Task StandbyMode_EndToEnd() await Task.Delay(2000); - // verify host logs - string hostLogDirectory = Path.Combine(webHostSettings.LogPath, "Host"); - string hostLogFilePath = Directory.EnumerateFiles(hostLogDirectory).First(); - string[] logLines = File.ReadAllLines(hostLogFilePath); + // verify logs + string[] logLines = traceWriter.Traces.Select(p => p.Message).ToArray(); Assert.Equal(2, logLines.Count(p => p.Contains("Host is in standby mode"))); Assert.Equal(1, logLines.Count(p => p.Contains("Stopping Host"))); Assert.Equal(2, logLines.Count(p => p.Contains("Executed 'Functions.WarmUp' (Succeeded"))); diff --git a/test/WebJobs.Script.Tests/WebHostResolverTests.cs b/test/WebJobs.Script.Tests/WebHostResolverTests.cs index 1b9828c3bf..e23933453f 100644 --- a/test/WebJobs.Script.Tests/WebHostResolverTests.cs +++ b/test/WebJobs.Script.Tests/WebHostResolverTests.cs @@ -44,13 +44,16 @@ public void GetScriptHostConfiguration_SetsHostId() } [Fact] - public void CreateStandbyScriptHostConfiguration_StandbyMode_ReturnsExpectedConfiguration() + public void CreateScriptHostConfiguration_StandbyMode_ReturnsExpectedConfiguration() { - var settings = new WebHostSettings(); + var settings = new WebHostSettings + { + IsSelfHost = true + }; - var config = WebHostResolver.CreateStandbyScriptHostConfiguration(settings); + var config = WebHostResolver.CreateScriptHostConfiguration(settings, true); - Assert.Equal(FileLoggingMode.Always, config.FileLoggingMode); + Assert.Equal(FileLoggingMode.DebugOnly, config.FileLoggingMode); Assert.Null(config.HostConfig.StorageConnectionString); Assert.Null(config.HostConfig.DashboardConnectionString); Assert.Equal(Path.Combine(Path.GetTempPath(), "Functions", "Standby"), config.RootScriptPath);