diff --git a/codecov.yml b/codecov.yml index 8883f4533..fd2eb0856 100644 --- a/codecov.yml +++ b/codecov.yml @@ -6,7 +6,9 @@ coverage: range: "70...95" status: - project: yes + project: + default: + threshold: 0.2% patch: default: target: 100% diff --git a/src/fdc3/dotnet/AppDirectory/test/MorganStanley.ComposeUI.Fdc3.AppDirectory.Tests/AppDirectory.GetApps.Tests.cs b/src/fdc3/dotnet/AppDirectory/test/MorganStanley.ComposeUI.Fdc3.AppDirectory.Tests/AppDirectory.GetApps.Tests.cs index 4a12bd728..dbbeaab73 100644 --- a/src/fdc3/dotnet/AppDirectory/test/MorganStanley.ComposeUI.Fdc3.AppDirectory.Tests/AppDirectory.GetApps.Tests.cs +++ b/src/fdc3/dotnet/AppDirectory/test/MorganStanley.ComposeUI.Fdc3.AppDirectory.Tests/AppDirectory.GetApps.Tests.cs @@ -17,7 +17,7 @@ using Moq.Contrib.HttpClient; using Finos.Fdc3.AppDirectory; using Newtonsoft.Json.Linq; -using TaskExtensions = MorganStanley.ComposeUI.Testing.TaskExtensions; +using System.Diagnostics; using System.IO.Abstractions; namespace MorganStanley.ComposeUI.Fdc3.AppDirectory; @@ -67,9 +67,18 @@ await fileSystem.File.WriteAllTextAsync( useApiSchema ? GetAppsApiResponseChanged : GetAppsJsonArrayChanged, Encoding.UTF8); - await TaskExtensions.WaitForBackgroundTasksAsync(TimeSpan.FromSeconds(20)); - - var apps = await appDirectory.GetApps(); + // Poll until the cache is invalidated and the updated data is returned + const int pollIntervalMs = 50; + var timeout = TimeSpan.FromSeconds(20); + var stopwatch = Stopwatch.StartNew(); + IEnumerable apps; + do + { + apps = await appDirectory.GetApps(); + if (apps.Count() == GetAppsExpectationChanged.Count) + break; + await Task.Delay(pollIntervalMs); + } while (stopwatch.Elapsed < timeout); apps.Should().BeEquivalentTo(GetAppsExpectationChanged); } diff --git a/src/fdc3/dotnet/DesktopAgent.Client/test/MorganStanley.ComposeUI.Fdc3.DesktopAgent.Client.Tests/Infrastructure/Internal/Protocol/PrivateChannel.Tests.cs b/src/fdc3/dotnet/DesktopAgent.Client/test/MorganStanley.ComposeUI.Fdc3.DesktopAgent.Client.Tests/Infrastructure/Internal/Protocol/PrivateChannel.Tests.cs index 78b1b466e..b3b52e800 100644 --- a/src/fdc3/dotnet/DesktopAgent.Client/test/MorganStanley.ComposeUI.Fdc3.DesktopAgent.Client.Tests/Infrastructure/Internal/Protocol/PrivateChannel.Tests.cs +++ b/src/fdc3/dotnet/DesktopAgent.Client/test/MorganStanley.ComposeUI.Fdc3.DesktopAgent.Client.Tests/Infrastructure/Internal/Protocol/PrivateChannel.Tests.cs @@ -33,7 +33,9 @@ public class PrivateChannelTests private readonly string _instanceId = "test-instance"; private readonly DisplayMetadata _displayMetadata = new(); private readonly PrivateChannel _channel; + private readonly TaskCompletionSource _disconnectTcs = new(TaskCreationOptions.RunContinuationsAsynchronously); private readonly JsonSerializerOptions _jsonSerializerOptions = SerializerOptionsHelper.JsonSerializerOptionsWithContextSerialization; + private static readonly TimeSpan DisconnectTimeout = TimeSpan.FromSeconds(5); public PrivateChannelTests() { @@ -45,7 +47,7 @@ public PrivateChannelTests() _channelId, _messagingMock.Object, _instanceId, - onDisconnect: () => { }, + onDisconnect: () => _disconnectTcs.TrySetResult(), isOriginalCreator: true); } @@ -53,8 +55,7 @@ public PrivateChannelTests() public async Task Broadcast_when_disconnected_throws() { _channel.Disconnect(); - - await Task.Delay(2000); + await _disconnectTcs.Task.WaitAsync(DisconnectTimeout); Func act = async () => await _channel.Broadcast(Mock.Of()); @@ -76,6 +77,7 @@ public async Task Broadcast_when_connected_calls_publish() public async Task AddContextListener_when_disconnected_throws() { _channel.Disconnect(); + await _disconnectTcs.Task.WaitAsync(DisconnectTimeout); Func act = async () => await _channel.AddContextListener(null, (ctx, ctxM) => { }); @@ -115,8 +117,7 @@ public void OnAddContextListener_when_connected_returns_listener() public async Task OnAddContextListener_when_disconnected_throws() { _channel.Disconnect(); - - await Task.Delay(2000); + await _disconnectTcs.Task.WaitAsync(DisconnectTimeout); Action act = () => _channel.OnAddContextListener(_ => { }); @@ -132,16 +133,18 @@ public void OnDisconnect_when_connected_returns_listener() } [Fact] - public void OnDisconnect_when_disconnected_throws() + public async Task OnDisconnect_when_disconnected_throws() { + var disconnectTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var channel = new PrivateChannel( _channelId, _messagingMock.Object, _instanceId, true, - () => { }); + () => disconnectTcs.TrySetResult()); channel.Disconnect(); + await disconnectTcs.Task.WaitAsync(DisconnectTimeout); Action act = () => channel.OnDisconnect(() => { }); @@ -160,8 +163,7 @@ public void OnUnsubscribe_when_connected_returns_listener() public async Task OnUnsubscribe_when_disconnected_throws() { _channel.Disconnect(); - - await Task.Delay(2000); + await _disconnectTcs.Task.WaitAsync(DisconnectTimeout); Action act = () => _channel.OnUnsubscribe(_ => { });