|
7 | 7 | using System.Linq;
|
8 | 8 | using System.Threading.Tasks;
|
9 | 9 | using Microsoft.Azure.WebJobs.Script.Tests;
|
| 10 | +using Newtonsoft.Json.Linq; |
10 | 11 | using Xunit;
|
11 | 12 |
|
12 | 13 | namespace Microsoft.Azure.WebJobs.Script.WebHost
|
@@ -46,19 +47,60 @@ public void SecretFilesArePurgedOnStartup()
|
46 | 47 | Assert.Equal("WebHookTrigger.json", secretFiles[3]);
|
47 | 48 | }
|
48 | 49 |
|
| 50 | + [Fact] |
| 51 | + public async Task EmptyHost_StartsSuccessfully() |
| 52 | + { |
| 53 | + string functionTestDir = Path.Combine(_fixture.TestFunctionRoot, Guid.NewGuid().ToString()); |
| 54 | + Directory.CreateDirectory(functionTestDir); |
| 55 | + |
| 56 | + // important for the repro that these directories no not exist |
| 57 | + string logDir = Path.Combine(_fixture.TestLogsRoot, Guid.NewGuid().ToString()); |
| 58 | + string secretsDir = Path.Combine(_fixture.TestSecretsRoot, Guid.NewGuid().ToString()); |
| 59 | + |
| 60 | + JObject hostConfig = new JObject |
| 61 | + { |
| 62 | + { "id", "123456" } |
| 63 | + }; |
| 64 | + File.WriteAllText(Path.Combine(functionTestDir, ScriptConstants.HostMetadataFileName), hostConfig.ToString()); |
| 65 | + |
| 66 | + ScriptHostConfiguration config = new ScriptHostConfiguration |
| 67 | + { |
| 68 | + RootScriptPath = functionTestDir, |
| 69 | + RootLogPath = logDir, |
| 70 | + FileLoggingEnabled = true |
| 71 | + }; |
| 72 | + SecretManager secretManager = new SecretManager(secretsDir); |
| 73 | + ScriptHostManager hostManager = new WebScriptHostManager(config, secretManager); |
| 74 | + |
| 75 | + Task runTask = Task.Run(() => hostManager.RunAndBlock()); |
| 76 | + |
| 77 | + await TestHelpers.Await(() => hostManager.IsRunning, timeout: 10000); |
| 78 | + |
| 79 | + hostManager.Stop(); |
| 80 | + Assert.False(hostManager.IsRunning); |
| 81 | + |
| 82 | + string hostLogFilePath = Directory.EnumerateFiles(Path.Combine(logDir, "Host")).Single(); |
| 83 | + string hostLogs = File.ReadAllText(hostLogFilePath); |
| 84 | + |
| 85 | + Assert.True(hostLogs.Contains("Generating 0 job function(s)")); |
| 86 | + Assert.True(hostLogs.Contains("No job functions found.")); |
| 87 | + Assert.True(hostLogs.Contains("Job host started")); |
| 88 | + Assert.True(hostLogs.Contains("Job host stopped")); |
| 89 | + } |
| 90 | + |
49 | 91 | public class Fixture : IDisposable
|
50 | 92 | {
|
51 | 93 | public Fixture()
|
52 | 94 | {
|
53 |
| - string testRoot = Path.Combine(Path.GetTempPath(), "FunctionTests"); |
54 |
| - if (Directory.Exists(testRoot)) |
55 |
| - { |
56 |
| - Directory.Delete(testRoot, recursive: true); |
57 |
| - } |
| 95 | + TestFunctionRoot = Path.Combine(TestHelpers.FunctionsTestDirectory, "Functions"); |
| 96 | + TestLogsRoot = Path.Combine(TestHelpers.FunctionsTestDirectory, "Logs"); |
| 97 | + TestSecretsRoot = Path.Combine(TestHelpers.FunctionsTestDirectory, "Secrets"); |
58 | 98 |
|
59 |
| - SecretsPath = Path.Combine(testRoot, "TestSecrets"); |
| 99 | + string testRoot = Path.Combine(TestFunctionRoot, Guid.NewGuid().ToString()); |
| 100 | + |
| 101 | + SecretsPath = Path.Combine(TestSecretsRoot, Guid.NewGuid().ToString()); |
60 | 102 | Directory.CreateDirectory(SecretsPath);
|
61 |
| - string logRoot = Path.Combine(testRoot, @"Functions"); |
| 103 | + string logRoot = Path.Combine(TestLogsRoot, Guid.NewGuid().ToString(), @"Functions"); |
62 | 104 | Directory.CreateDirectory(logRoot);
|
63 | 105 | FunctionsLogDir = Path.Combine(logRoot, @"Function");
|
64 | 106 | Directory.CreateDirectory(FunctionsLogDir);
|
@@ -100,13 +142,31 @@ public Fixture()
|
100 | 142 |
|
101 | 143 | public string SecretsPath { get; private set; }
|
102 | 144 |
|
| 145 | + public string TestFunctionRoot { get; private set; } |
| 146 | + |
| 147 | + public string TestLogsRoot { get; private set; } |
| 148 | + |
| 149 | + public string TestSecretsRoot { get; private set; } |
| 150 | + |
103 | 151 | public void Dispose()
|
104 | 152 | {
|
105 | 153 | if (HostManager != null)
|
106 | 154 | {
|
107 | 155 | HostManager.Stop();
|
108 | 156 | HostManager.Dispose();
|
109 | 157 | }
|
| 158 | + |
| 159 | + try |
| 160 | + { |
| 161 | + if (Directory.Exists(TestHelpers.FunctionsTestDirectory)) |
| 162 | + { |
| 163 | + Directory.Delete(TestHelpers.FunctionsTestDirectory, recursive: true); |
| 164 | + } |
| 165 | + } |
| 166 | + catch |
| 167 | + { |
| 168 | + // occasionally get file in use errors |
| 169 | + } |
110 | 170 | }
|
111 | 171 |
|
112 | 172 | private void CreateTestFunctionLogs(string logRoot, string functionName)
|
|
0 commit comments