Skip to content

Commit

Permalink
Fix StandBy mode bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mathewc committed Sep 15, 2017
1 parent 4f5da41 commit f33b946
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
28 changes: 12 additions & 16 deletions src/WebJobs.Script.WebHost/App_Start/WebHostResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
Expand Down
11 changes: 7 additions & 4 deletions test/WebJobs.Script.Tests/WebHostResolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f33b946

Please sign in to comment.