Skip to content

Commit ef637e5

Browse files
committed
adding more logging to StandyMode test
1 parent a58302a commit ef637e5

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

test/WebJobs.Script.Tests.Integration/Host/ScriptHostManagerTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,15 @@ public async Task RenameFunctionAndRestart()
153153
{
154154
// don't start until the manager is running
155155
TestHelpers.Await(() => manager.State == ScriptHostState.Running,
156-
userMessage: "Host did not start in time.").Wait();
156+
userMessageCallback: () => "Host did not start in time.").Wait();
157157

158158
// Wait for initial execution.
159159
TestHelpers.Await(() =>
160160
{
161161
bool exists = blob.Exists();
162162
pollMessages.Add($"TimerTrigger: [{DateTime.UtcNow.ToString("HH:mm:ss.fff")}] '{blob.Uri}' exists: {exists}");
163163
return exists;
164-
}, timeout: 10 * 1000, userMessage: $"Blob '{blob.Uri}' was not created by 'TimerTrigger' in time.").Wait();
164+
}, timeout: 10 * 1000, userMessageCallback: () => $"Blob '{blob.Uri}' was not created by 'TimerTrigger' in time.").Wait();
165165

166166
// find __dirname from blob
167167
string text;
@@ -186,7 +186,7 @@ public async Task RenameFunctionAndRestart()
186186
bool exists = blob.Exists();
187187
pollMessages.Add($"MovedTrigger: [{DateTime.UtcNow.ToString("HH:mm:ss.fff")}] '{blob.Uri}' exists: {exists}");
188188
return exists;
189-
}, timeout: 30 * 1000, userMessage: $"Blob '{blob.Uri}' was not created by 'MovedTrigger' in time.").Wait();
189+
}, timeout: 30 * 1000, userMessageCallback: () => $"Blob '{blob.Uri}' was not created by 'MovedTrigger' in time.").Wait();
190190

191191
using (var stream = new MemoryStream())
192192
{

test/WebJobs.Script.Tests.Integration/Host/StandbyManagerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ await TestHelpers.Await(() =>
128128
// wait for the trace indicating that the host has been specialized
129129
logLines = traceWriter.GetTraces().Select(p => p.Message).ToArray();
130130
return logLines.Contains("Generating 0 job function(s)");
131-
});
131+
}, userMessageCallback: () => string.Join(Environment.NewLine, traceWriter.GetTraces().Select(p => p.Message)));
132132

133133
// verify the rest of the expected logs
134134
string text = string.Join(Environment.NewLine, logLines);

test/WebJobs.Script.Tests.Integration/Host/WebScriptHostManagerTimeoutTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public async Task OnTimeoutException_IgnoreToken_StopsManager()
2828

2929
await RunTimeoutExceptionTest(trace, handleCancellation: false);
3030

31-
await TestHelpers.Await(() => !(_manager.State == ScriptHostState.Running), userMessage: "Expected host to not be running");
31+
await TestHelpers.Await(() => !(_manager.State == ScriptHostState.Running), userMessageCallback: () => "Expected host to not be running");
3232

3333
var traces = trace.GetTraces();
3434
Assert.DoesNotContain(traces, t => t.Message.StartsWith("Done"));
@@ -45,7 +45,7 @@ public async Task OnTimeoutException_UsesToken_ManagerKeepsRunning()
4545

4646
// wait a few seconds to make sure the manager doesn't die
4747
await Assert.ThrowsAsync<ApplicationException>(() => TestHelpers.Await(() => !(_manager.State == ScriptHostState.Running),
48-
timeout: 3000, throwWhenDebugging: true, userMessage: "Expected host manager not to die"));
48+
timeout: 3000, throwWhenDebugging: true, userMessageCallback: () => "Expected host manager not to die"));
4949

5050
var traces = trace.GetTraces();
5151
Assert.Contains(traces, t => t.Message.StartsWith("Done"));
@@ -83,7 +83,7 @@ private async Task<WebScriptHostManager> CreateAndStartWebScriptHostManager(Trac
8383
var mockEventManager = new Mock<IScriptEventManager>();
8484
var manager = new WebScriptHostManager(config, new TestSecretManagerFactory(), mockEventManager.Object, ScriptSettingsManager.Instance, new WebHostSettings { SecretsPath = _secretsDirectory.Path });
8585
Task task = Task.Run(() => { manager.RunAndBlock(); });
86-
await TestHelpers.Await(() => manager.State == ScriptHostState.Running, userMessage: "Expected host to be running");
86+
await TestHelpers.Await(() => manager.State == ScriptHostState.Running, userMessageCallback: () => "Expected host to be running");
8787

8888
return manager;
8989
}

test/WebJobs.Script.Tests.Shared/TestHelpers.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static string NewRandomString(int length = 10)
4444
.ToArray());
4545
}
4646

47-
public static async Task Await(Func<bool> condition, int timeout = 60 * 1000, int pollingInterval = 2 * 1000, bool throwWhenDebugging = false, string userMessage = null)
47+
public static async Task Await(Func<bool> condition, int timeout = 60 * 1000, int pollingInterval = 2 * 1000, bool throwWhenDebugging = false, Func<string> userMessageCallback = null)
4848
{
4949
DateTime start = DateTime.Now;
5050
while (!condition())
@@ -55,9 +55,9 @@ public static async Task Await(Func<bool> condition, int timeout = 60 * 1000, in
5555
if (shouldThrow && (DateTime.Now - start).TotalMilliseconds > timeout)
5656
{
5757
string error = "Condition not reached within timeout.";
58-
if (userMessage != null)
58+
if (userMessageCallback != null)
5959
{
60-
error += " " + userMessage;
60+
error += " " + userMessageCallback();
6161
}
6262
throw new ApplicationException(error);
6363
}

0 commit comments

Comments
 (0)