Skip to content

Commit

Permalink
Fix(tests): Replace ConfigureAwait(false) with ConfigureAwait(true)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
maxisoft committed Mar 6, 2025
1 parent 0f708d3 commit 802aa20
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using ASFFreeGames.Configurations;
using Xunit;

Expand All @@ -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
Expand All @@ -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;
Expand Down
34 changes: 17 additions & 17 deletions ASFFreeGames.Tests/Reddit/RedditHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ 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);
}

[Theory]
[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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions ASFFreeGames.Tests/Redlib/RedlibHtmlParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RedlibGameEntry> result = RedlibHtmlParser.ParseGamesFromHtml(html, dedup: false);
Expand Down
4 changes: 2 additions & 2 deletions ASFFreeGames.Tests/Redlib/RedlibInstancesListTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Uri> uris = await RedlibInstanceList.ListFromEmbedded(default(CancellationToken)).ConfigureAwait(false);
List<Uri> uris = await RedlibInstanceList.ListFromEmbedded(CancellationToken.None).ConfigureAwait(true);

Assert.NotEmpty(uris);
}
Expand Down

0 comments on commit 802aa20

Please sign in to comment.