Skip to content

Commit 61c075e

Browse files
authored
Flaky test: FunctionsSyncServiceTests: Increase test due time & add tsc callback (#10146)
1 parent 1bf0813 commit 61c075e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

test/WebJobs.Script.Tests/FunctionsSyncServiceTests.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class FunctionsSyncServiceTests
2424
private readonly Mock<IFunctionsSyncManager> _mockSyncManager;
2525
private readonly Mock<IScriptWebHostEnvironment> _mockWebHostEnvironment;
2626
private readonly Mock<IEnvironment> _mockEnvironment;
27-
private readonly int _testDueTime = 250;
27+
private readonly int _testDueTime = 1000;
2828

2929
public FunctionsSyncServiceTests()
3030
{
@@ -38,7 +38,6 @@ public FunctionsSyncServiceTests()
3838

3939
_mockPrimaryHostStateProviderMock.Setup(p => p.IsPrimary).Returns(true);
4040
_mockScriptHostManager.Setup(p => p.State).Returns(ScriptHostState.Running);
41-
_mockSyncManager.Setup(p => p.TrySyncTriggersAsync(true)).ReturnsAsync(new SyncTriggersResult { Success = true });
4241

4342
_mockWebHostEnvironment = new Mock<IScriptWebHostEnvironment>(MockBehavior.Strict);
4443
_mockWebHostEnvironment.SetupGet(p => p.InStandbyMode).Returns(false);
@@ -67,9 +66,12 @@ public void ShouldSyncTriggers_ReturnsExpectedResult(bool isPrimary, ScriptHostS
6766
[Fact]
6867
public async Task StartAsync_PrimaryHost_Running_SyncsTriggers_AfterTimeout()
6968
{
69+
TaskCompletionSource syncTriggers = new TaskCompletionSource();
70+
_mockSyncManager.Setup(p => p.TrySyncTriggersAsync(true)).ReturnsAsync(new SyncTriggersResult { Success = true }).Callback(() => syncTriggers.TrySetResult());
71+
7072
await _syncService.StartAsync(CancellationToken.None);
71-
await Task.Delay(2 * _testDueTime);
7273

74+
await syncTriggers.Task.WaitAsync(TimeSpan.FromMilliseconds(2 * _testDueTime));
7375
_mockSyncManager.Verify(p => p.TrySyncTriggersAsync(true), Times.Once);
7476

7577
var logMessage = _loggerProvider.GetAllLogMessages().Select(p => p.FormattedMessage).Single();
@@ -100,11 +102,12 @@ public async Task StopCalledBeforeTimeout_DoesNotSyncTriggers()
100102
[Fact]
101103
public async Task UnhandledExceptions_HandledInCallback()
102104
{
103-
_mockSyncManager.Setup(p => p.TrySyncTriggersAsync(true)).ThrowsAsync(new Exception("Kaboom!"));
105+
TaskCompletionSource syncTriggers = new TaskCompletionSource();
106+
_mockSyncManager.Setup(p => p.TrySyncTriggersAsync(true)).ThrowsAsync(new Exception("Kaboom!")).Callback(() => syncTriggers.TrySetResult());
104107

105108
await _syncService.StartAsync(CancellationToken.None);
106-
await Task.Delay(2 * _testDueTime);
107109

110+
await syncTriggers.Task.WaitAsync(TimeSpan.FromMilliseconds(2 * _testDueTime));
108111
_mockSyncManager.Verify(p => p.TrySyncTriggersAsync(true), Times.Once);
109112
}
110113

0 commit comments

Comments
 (0)