diff --git a/test/WebJobs.Script.Tests/FileTraceWriterTests.cs b/test/WebJobs.Script.Tests/FileTraceWriterTests.cs index 902c0f702c..af9b5d1208 100644 --- a/test/WebJobs.Script.Tests/FileTraceWriterTests.cs +++ b/test/WebJobs.Script.Tests/FileTraceWriterTests.cs @@ -49,7 +49,7 @@ await Task.WhenAll( } [Fact] - public void SetNewLogFile_PurgesOldLogFiles() + public async Task SetNewLogFile_PurgesOldLogFiles() { DirectoryInfo directory = new DirectoryInfo(_logFilePath); directory.Create(); @@ -83,9 +83,14 @@ public void SetNewLogFile_PurgesOldLogFiles() files = directory.GetFiles().OrderByDescending(p => p.LastWriteTime).ToArray(); + await TestHelpers.Await(() => + { + files = directory.GetFiles().OrderByDescending(p => p.LastWriteTime).ToArray(); + return files.Length == 2; + }, timeout: 2000); + // verify the correct log files were purged and the 2 // most recent files were retained - Assert.Equal(2, files.Length); Assert.True(files[0].Name.StartsWith("4")); Assert.True(files[1].Name.StartsWith("3")); }