fix(ci): Resolve race conditions in tests and fix unused variable warning

- Refactored Torrents.cs to use local DbSettings instead of global Settings.Get

- Removed unused exception variable in Torrents.cs

- Disabled xUnit parallelization globally to prevent test race conditions caused by shared global state

- Enforced sequential test execution in CI workflow
This commit is contained in:
Antonin Lenfant-Kodia 2026-05-17 23:26:17 +02:00
parent d68b8b9bfe
commit 8e49e500ea
5 changed files with 23 additions and 17 deletions

View file

@ -21,4 +21,4 @@ jobs:
- name: Build
run: dotnet build --no-restore server
- name: Test
run: dotnet test --no-build --verbosity normal server
run: dotnet test --no-build --verbosity normal -maxcpucount:1 server

View file

@ -0,0 +1,3 @@
using Xunit;
[assembly: CollectionBehavior(DisableParallelization = true)]

View file

@ -96,7 +96,7 @@ public class TorrentsTest
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Settings.Get.DownloadClient.DownloadPath = settings.DownloadClient.DownloadPath = @"C:\Downloads";
settings.DownloadClient.DownloadPath = @"C:\Downloads";
}
var downloadPath = Path.Combine(settings.DownloadClient.DownloadPath, category);
@ -165,9 +165,9 @@ public class TorrentsTest
mocks.TorrentDataMock.Setup(t => t.GetById(torrent.TorrentId)).Returns(Task.FromResult<Torrent?>(torrent));
mocks.DownloadsMock.Setup(d => d.GetForTorrent(torrent.TorrentId)).ReturnsAsync(downloads);
var downloadPath = $"{settings.DownloadClient.DownloadPath}/{torrent.Category}";
var torrentPath = $"{downloadPath}/{torrent.RdName}";
var filePath = $"{torrentPath}/{downloads[0].FileName}";
var downloadPath = Path.Combine(settings.DownloadClient.DownloadPath, torrent.Category ?? "");
var torrentPath = Path.Combine(downloadPath, torrent.RdName ?? "");
var filePath = Path.Combine(torrentPath, downloads[0].FileName ?? "");
var fileSystemMock = new MockFileSystem(new Dictionary<String, MockFileData>
{
@ -213,9 +213,9 @@ public class TorrentsTest
mocks.TorrentDataMock.Setup(t => t.GetById(torrent.TorrentId)).Returns(Task.FromResult<Torrent?>(torrent));
mocks.DownloadsMock.Setup(d => d.GetForTorrent(torrent.TorrentId)).ReturnsAsync(downloads);
var downloadPath = $"{settings.DownloadClient.DownloadPath}/{torrent.Category}";
var torrentPath = $"{downloadPath}/{torrent.RdName}";
var filePath = $"{torrentPath}/{downloads[0].FileName}";
var downloadPath = Path.Combine(settings.DownloadClient.DownloadPath, torrent.Category ?? "");
var torrentPath = Path.Combine(downloadPath, torrent.RdName ?? "");
var filePath = Path.Combine(torrentPath, downloads[0].FileName ?? "");
var fileSystemMock = new MockFileSystem(new Dictionary<String, MockFileData>
{
@ -280,9 +280,9 @@ public class TorrentsTest
mocks.TorrentDataMock.Setup(t => t.GetById(torrent.TorrentId)).Returns(Task.FromResult<Torrent?>(torrent));
mocks.DownloadsMock.Setup(d => d.GetForTorrent(torrent.TorrentId)).ReturnsAsync(downloads);
var downloadPath = $"{settings.DownloadClient.DownloadPath}/{torrent.Category}";
var torrentPath = $"{downloadPath}/{torrent.RdName}";
var filePath = $"{torrentPath}/{downloads[0].FileName}";
var downloadPath = Path.Combine(settings.DownloadClient.DownloadPath, torrent.Category ?? "");
var torrentPath = Path.Combine(downloadPath, torrent.RdName ?? "");
var filePath = Path.Combine(torrentPath, downloads[0].FileName ?? "");
var fileSystemMock = new MockFileSystem(new Dictionary<String, MockFileData>
{

View file

@ -569,7 +569,7 @@ public class Torrents(
if (deleteLocalFiles && !String.IsNullOrWhiteSpace(torrent.RdName))
{
var downloadPath = DownloadPath(torrent);
var downloadPath = DownloadPath(torrent, Settings.Get);
downloadPath = Path.Combine(downloadPath, torrent.RdName);
Log($"Deleting local files in {downloadPath}", torrent);
@ -828,7 +828,7 @@ public class Torrents(
await Task.Delay(100);
}
var downloadPath = DownloadPath(download.Torrent!);
var downloadPath = DownloadPath(download.Torrent!, Settings.Get);
var filePath = DownloadHelper.GetDownloadPath(downloadPath, download.Torrent!, download);
@ -929,9 +929,9 @@ public class Torrents(
return torrent;
}
private static String DownloadPath(Torrent torrent)
private static String DownloadPath(Torrent torrent, DbSettings settings)
{
var settingDownloadPath = Settings.Get.DownloadClient.DownloadPath;
var settingDownloadPath = settings.DownloadClient.DownloadPath;
if (!String.IsNullOrWhiteSpace(torrent.Category))
{
@ -988,7 +988,7 @@ public class Torrents(
Log($"Parsing external program {fileName} with arguments {arguments}", torrent);
var downloadPath = DownloadPath(torrent);
var downloadPath = DownloadPath(torrent, settings);
var torrentPath = Path.Combine(downloadPath, torrent.RdName ?? "Unknown");
var filePath = torrentPath;
@ -1083,7 +1083,7 @@ public class Torrents(
await torrentData.UpdateRdData(torrent);
}
}
catch (Exception ex)
catch (Exception)
{
// ignored
}

View file

@ -0,0 +1,3 @@
using Xunit;
[assembly: CollectionBehavior(DisableParallelization = true)]