From 802aa2097032f168214fe8d50b31bb9241103b9b Mon Sep 17 00:00:00 2001 From: maxisoft Date: Thu, 6 Mar 2025 20:40:21 +0100 Subject: [PATCH] Fix(tests): Replace `ConfigureAwait(false)` with `ConfigureAwait(true)` The xUnit analyzer (xUnit1030) recommends against using `ConfigureAwait(false)` in test methods, as it can negatively impact test parallelization. This commit addresses the analyzer warnings by replacing all instances of `ConfigureAwait(false)` with `ConfigureAwait(true)` within test methods. This ensures tests are executed in a way that respects parallelization limits and aligns with xUnit best practices for asynchronous testing. This change should resolve the reported build warnings and potentially improve test execution reliability. --- .../ASFFreeGamesOptionsSaverTests.cs | 5 +-- .../Reddit/RedditHelperTests.cs | 34 +++++++++---------- .../Redlib/RedlibHtmlParserTests.cs | 4 +-- .../Redlib/RedlibInstancesListTests.cs | 4 +-- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/ASFFreeGames.Tests/Configurations/ASFFreeGamesOptionsSaverTests.cs b/ASFFreeGames.Tests/Configurations/ASFFreeGamesOptionsSaverTests.cs index e809bbd..ec54e6f 100644 --- a/ASFFreeGames.Tests/Configurations/ASFFreeGamesOptionsSaverTests.cs +++ b/ASFFreeGames.Tests/Configurations/ASFFreeGamesOptionsSaverTests.cs @@ -3,6 +3,7 @@ using System.IO; using System.Text; using System.Text.Json; +using System.Threading.Tasks; using ASFFreeGames.Configurations; using Xunit; @@ -11,7 +12,7 @@ namespace Maxisoft.ASF.Tests.Configurations; public class ASFFreeGamesOptionsSaverTests { [Fact] #pragma warning disable CA1707 - public async void SaveOptions_WritesValidJson_And_ParsesCorrectly() { + public async Task SaveOptions_WritesValidJson_And_ParsesCorrectly() { #pragma warning restore CA1707 // Arrange @@ -34,7 +35,7 @@ public async void SaveOptions_WritesValidJson_And_ParsesCorrectly() { using MemoryStream memoryStream = new(); // Act - _ = await ASFFreeGamesOptionsSaver.SaveOptions(memoryStream, options).ConfigureAwait(false); + _ = await ASFFreeGamesOptionsSaver.SaveOptions(memoryStream, options).ConfigureAwait(true); // Assert - Validate UTF-8 encoding memoryStream.Position = 0; diff --git a/ASFFreeGames.Tests/Reddit/RedditHelperTests.cs b/ASFFreeGames.Tests/Reddit/RedditHelperTests.cs index 1c74d02..7b10563 100644 --- a/ASFFreeGames.Tests/Reddit/RedditHelperTests.cs +++ b/ASFFreeGames.Tests/Reddit/RedditHelperTests.cs @@ -16,7 +16,7 @@ namespace Maxisoft.ASF.Tests.Reddit; public sealed class RedditHelperTests { [Fact] public async Task TestNotEmpty() { - RedditGameEntry[] entries = await LoadAsfinfoEntries().ConfigureAwait(false); + RedditGameEntry[] entries = await LoadAsfinfoEntries().ConfigureAwait(true); Assert.NotEmpty(entries); } @@ -24,13 +24,13 @@ public async Task TestNotEmpty() { [InlineData("s/762440")] [InlineData("a/1601550")] public async Task TestContains(string appid) { - RedditGameEntry[] entries = await LoadAsfinfoEntries().ConfigureAwait(false); + RedditGameEntry[] entries = await LoadAsfinfoEntries().ConfigureAwait(true); Assert.Contains(new RedditGameEntry(appid, default(ERedditGameEntryKind), long.MaxValue), entries, new GameEntryIdentifierEqualityComparer()); } [Fact] public async Task TestMaintainOrder() { - RedditGameEntry[] entries = await LoadAsfinfoEntries().ConfigureAwait(false); + RedditGameEntry[] entries = await LoadAsfinfoEntries().ConfigureAwait(true); int app762440 = Array.FindIndex(entries, static entry => entry.Identifier == "s/762440"); int app1601550 = Array.FindIndex(entries, static entry => entry.Identifier == "a/1601550"); Assert.InRange(app762440, 0, long.MaxValue); @@ -43,17 +43,17 @@ public async Task TestMaintainOrder() { [Fact] public async Task TestFreeToPlayParsing() { - RedditGameEntry[] entries = await LoadAsfinfoEntries().ConfigureAwait(false); - RedditGameEntry f2pEntry = Array.Find(entries, static entry => entry.Identifier == "a/1631250"); - Assert.True(f2pEntry.IsFreeToPlay); + RedditGameEntry[] entries = await LoadAsfinfoEntries().ConfigureAwait(true); + RedditGameEntry f2PEntry = Array.Find(entries, static entry => entry.Identifier == "a/1631250"); + Assert.True(f2PEntry.IsFreeToPlay); RedditGameEntry getEntry(string identifier) => Array.Find(entries, entry => entry.Identifier == identifier); - f2pEntry = getEntry("a/431650"); // F2P - Assert.True(f2pEntry.IsFreeToPlay); + f2PEntry = getEntry("a/431650"); // F2P + Assert.True(f2PEntry.IsFreeToPlay); - f2pEntry = getEntry("a/579730"); - Assert.True(f2pEntry.IsFreeToPlay); + f2PEntry = getEntry("a/579730"); + Assert.True(f2PEntry.IsFreeToPlay); RedditGameEntry dlcEntry = getEntry("s/791643"); // DLC Assert.False(dlcEntry.IsFreeToPlay); @@ -70,17 +70,17 @@ public async Task TestFreeToPlayParsing() { [Fact] public async Task TestDlcParsing() { - RedditGameEntry[] entries = await LoadAsfinfoEntries().ConfigureAwait(false); - RedditGameEntry f2pEntry = Array.Find(entries, static entry => entry.Identifier == "a/1631250"); - Assert.False(f2pEntry.IsForDlc); + RedditGameEntry[] entries = await LoadAsfinfoEntries().ConfigureAwait(true); + RedditGameEntry f2PEntry = Array.Find(entries, static entry => entry.Identifier == "a/1631250"); + Assert.False(f2PEntry.IsForDlc); RedditGameEntry getEntry(string identifier) => Array.Find(entries, entry => entry.Identifier == identifier); - f2pEntry = getEntry("a/431650"); // F2P - Assert.False(f2pEntry.IsForDlc); + f2PEntry = getEntry("a/431650"); // F2P + Assert.False(f2PEntry.IsForDlc); - f2pEntry = getEntry("a/579730"); - Assert.False(f2pEntry.IsForDlc); + f2PEntry = getEntry("a/579730"); + Assert.False(f2PEntry.IsForDlc); RedditGameEntry dlcEntry = getEntry("s/791643"); // DLC Assert.True(dlcEntry.IsForDlc); diff --git a/ASFFreeGames.Tests/Redlib/RedlibHtmlParserTests.cs b/ASFFreeGames.Tests/Redlib/RedlibHtmlParserTests.cs index 7b43d9c..b43d59a 100644 --- a/ASFFreeGames.Tests/Redlib/RedlibHtmlParserTests.cs +++ b/ASFFreeGames.Tests/Redlib/RedlibHtmlParserTests.cs @@ -13,8 +13,8 @@ namespace Maxisoft.ASF.Tests.Redlib; public class RedlibHtmlParserTests { [Fact] - public async void Test() { - string html = await LoadHtml().ConfigureAwait(false); + public async Task Test() { + string html = await LoadHtml().ConfigureAwait(true); // ReSharper disable once ArgumentsStyleLiteral IReadOnlyCollection result = RedlibHtmlParser.ParseGamesFromHtml(html, dedup: false); diff --git a/ASFFreeGames.Tests/Redlib/RedlibInstancesListTests.cs b/ASFFreeGames.Tests/Redlib/RedlibInstancesListTests.cs index 86b025f..bd69fb6 100644 --- a/ASFFreeGames.Tests/Redlib/RedlibInstancesListTests.cs +++ b/ASFFreeGames.Tests/Redlib/RedlibInstancesListTests.cs @@ -15,9 +15,9 @@ namespace Maxisoft.ASF.Tests.Redlib; public class RedlibInstanceListTests { [Fact] - public async void Test() { + public async Task Test() { RedlibInstanceList lister = new(new ASFFreeGamesOptions()); - List uris = await RedlibInstanceList.ListFromEmbedded(default(CancellationToken)).ConfigureAwait(false); + List uris = await RedlibInstanceList.ListFromEmbedded(CancellationToken.None).ConfigureAwait(true); Assert.NotEmpty(uris); }