Skip to content

Commit 5c8e2f2

Browse files
committed
Fixing flaky tests
1 parent 8457985 commit 5c8e2f2

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

src/WebJobs.Script/Description/Node/NodeFunctionInvoker.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,17 @@ private Dictionary<string, object> CreateScriptExecutionContext(object input, Da
261261
string text = p as string;
262262
if (text != null)
263263
{
264-
traceWriter.Info(text);
265-
fileTraceWriter.Info(text);
264+
try
265+
{
266+
fileTraceWriter.Info(text);
267+
traceWriter.Info(text);
268+
}
269+
catch (ObjectDisposedException)
270+
{
271+
// if a function attempts to write to a disposed
272+
// TraceWriter. Might happen if a function tries to
273+
// log after calling done()
274+
}
266275
}
267276

268277
return Task.FromResult<object>(null);

test/WebJobs.Script.Tests/NodeEndToEndTests.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,19 +220,20 @@ public async Task Scenario_DoneCalledMultipleTimes_ErrorIsLogged()
220220
{
221221
{ "input", input.ToString() }
222222
};
223-
await Fixture.Host.CallAsync("Scenarios", arguments);
224223

225-
var logs = await TestHelpers.GetFunctionLogsAsync("Scenarios");
224+
// call a few times since this is a timing related error
225+
for (int i = 0; i < 3; i++)
226+
{
227+
await Fixture.Host.CallAsync("Scenarios", arguments);
228+
}
226229

227-
Assert.Equal(4, logs.Count);
228-
Assert.True(logs.Any(p => p.Contains("Function started")));
229-
Assert.True(logs.Any(p => p.Contains("Running scenario 'doubleDone'")));
230+
var logs = await TestHelpers.GetFunctionLogsAsync("Scenarios");
230231

231-
// verify an error was written
232+
// verify an error was written at least once
232233
Assert.True(logs.Any(p => p.Contains("Error: 'done' has already been called. Please check your script for extraneous calls to 'done'.")));
233234

234-
// verify the function completed successfully
235-
Assert.True(logs.Any(p => p.Contains("Function completed (Success")));
235+
// verify the function completed successfully each time
236+
Assert.Equal(3, logs.Count(p => p.Contains("Function completed (Success")));
236237
}
237238

238239
[Fact]

test/WebJobs.Script.Tests/ScriptHostManagerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ public void RunAndBlock_DisposesOfHost_WhenExceptionIsThrown()
9696
hostMock.Protected().Verify("Dispose", Times.Once(), true);
9797
}
9898

99-
/*
10099
[Fact]
101100
public async Task RunAndBlock_SetsLastError_WhenExceptionIsThrown()
102101
{
@@ -141,7 +140,6 @@ await TestHelpers.Await(() =>
141140

142141
Assert.Null(mockHostManager.Object.LastError);
143142
}
144-
*/
145143

146144
[Fact]
147145
public async Task EmptyHost_StartsSuccessfully()
@@ -173,6 +171,8 @@ public async Task EmptyHost_StartsSuccessfully()
173171
hostManager.Stop();
174172
Assert.False(hostManager.IsRunning);
175173

174+
await Task.Delay(FileTraceWriter.LogFlushIntervalMs);
175+
176176
string hostLogFilePath = Directory.EnumerateFiles(Path.Combine(logDir, "Host")).Single();
177177
string hostLogs = File.ReadAllText(hostLogFilePath);
178178

0 commit comments

Comments
 (0)