Skip to content

Commit

Permalink
Address flaky TestAppOfflineDebounceTime test (Azure#10128)
Browse files Browse the repository at this point in the history
* Address flaky test

* Fix callback
  • Loading branch information
jviau authored May 30, 2024
1 parent 80dd177 commit 3d401d3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions test/WebJobs.Script.Tests/FileMonitoringServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,15 @@ public static async Task TestAppOfflineDebounceTime(string fileName, int delayIn
WatchFiles = { "host.json" }
};
var loggerFactory = new LoggerFactory();

TaskCompletionSource stop = new TaskCompletionSource();
var mockApplicationLifetime = new Mock<IApplicationLifetime>();
mockApplicationLifetime.Setup(m => m.StopApplication()).Callback(() => stop.TrySetResult());

TaskCompletionSource restart = new TaskCompletionSource();
var mockScriptHostManager = new Mock<IScriptHostManager>();
mockScriptHostManager.Setup(m => m.RestartHostAsync(default)).Callback(() => restart.TrySetResult());

var mockEventManager = new ScriptEventManager();
var environment = new TestEnvironment();

Expand All @@ -311,18 +318,19 @@ public static async Task TestAppOfflineDebounceTime(string fileName, int delayIn
await fileMonitoringService.StartAsync(new CancellationToken(canceled: false));

var offlineEventArgs = new FileSystemEventArgs(WatcherChangeTypes.Created, tempDir, fileName);
FileEvent offlinefileEvent = new FileEvent("ScriptFiles", offlineEventArgs);
FileEvent offlineFileEvent = new FileEvent("ScriptFiles", offlineEventArgs);

var randomFileEventArgs = new FileSystemEventArgs(WatcherChangeTypes.Created, tempDir, "random.txt");
FileEvent randomFileEvent = new FileEvent("ScriptFiles", randomFileEventArgs);

mockEventManager.Publish(offlinefileEvent);
mockEventManager.Publish(offlineFileEvent);
await Task.Delay(delayInMs);
mockEventManager.Publish(randomFileEvent);

// Test
if (expectShutdown)
{
await stop.Task.WaitAsync(TimeSpan.FromSeconds(5));
mockApplicationLifetime.Verify(m => m.StopApplication());
}
else
Expand All @@ -332,6 +340,7 @@ public static async Task TestAppOfflineDebounceTime(string fileName, int delayIn

if (expectRestart)
{
await restart.Task.WaitAsync(TimeSpan.FromSeconds(5));
mockScriptHostManager.Verify(m => m.RestartHostAsync(default));
}
else
Expand Down

0 comments on commit 3d401d3

Please sign in to comment.