From 6ece6697baaf1323e511244697d82e663b39888b Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Sat, 8 Jul 2023 13:55:30 -0400 Subject: [PATCH] Fix a bunch of tests being inconclusive in CI --- .github/workflows/ci-pipeline.yml | 8 +-- .../Live/TestLiveServer.cs | 1 + tests/Tgstation.Server.Tests/TestDatabase.cs | 1 + .../Tgstation.Server.Tests/TestRepository.cs | 60 +++++++++++-------- 4 files changed, 42 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci-pipeline.yml b/.github/workflows/ci-pipeline.yml index 1c6ea2231d..a6aed6d9d8 100644 --- a/.github/workflows/ci-pipeline.yml +++ b/.github/workflows/ci-pipeline.yml @@ -257,7 +257,7 @@ jobs: run: dotnet build -c ${{ matrix.configuration }}NoWindows - name: Run Unit Tests - run: sudo dotnet test --no-build --logger "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true" --filter FullyQualifiedName!~TestLiveServer -c ${{ matrix.configuration }}NoWindows --collect:"XPlat Code Coverage" --settings build/ci.runsettings --results-directory ./TestResults tgstation-server.sln + run: sudo dotnet test --no-build --logger "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true" --filter TestCategory!=RequiresDatabase -c ${{ matrix.configuration }}NoWindows --collect:"XPlat Code Coverage" --settings build/ci.runsettings --results-directory ./TestResults tgstation-server.sln - name: Store Code Coverage uses: actions/upload-artifact@v3 @@ -300,7 +300,7 @@ jobs: run: dotnet build -c ${{ matrix.configuration }}NoWix - name: Run Unit Tests - run: dotnet test --no-build --logger "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true" --filter FullyQualifiedName!~TestLiveServer -c ${{ matrix.configuration }}NoWix --collect:"XPlat Code Coverage" --settings build/ci.runsettings --results-directory ./TestResults tgstation-server.sln + run: dotnet test --no-build --logger "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true" --filter TestCategory!=RequiresDatabase -c ${{ matrix.configuration }}NoWix --collect:"XPlat Code Coverage" --settings build/ci.runsettings --results-directory ./TestResults tgstation-server.sln - name: Store Code Coverage uses: actions/upload-artifact@v3 @@ -415,7 +415,7 @@ jobs: run: | cd tests/Tgstation.Server.Tests Start-Sleep -Seconds 10 - dotnet test -c ${{ matrix.configuration }} --no-build --filter FullyQualifiedName~TestLiveServer --logger "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true" --collect:"XPlat Code Coverage" --settings ../../build/ci.runsettings --results-directory ../../TestResults + dotnet test -c ${{ matrix.configuration }} --no-build --filter TestCategory=RequiresDatabase --logger "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true" --collect:"XPlat Code Coverage" --settings ../../build/ci.runsettings --results-directory ../../TestResults - name: Store Code Coverage uses: actions/upload-artifact@v3 @@ -584,7 +584,7 @@ jobs: run: | cd tests/Tgstation.Server.Tests sleep 10 - dotnet test -c ${{ matrix.configuration }}NoWindows --filter FullyQualifiedName~TestLiveServer --logger "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true" --no-build --collect:"XPlat Code Coverage" --settings ../../build/ci.runsettings --results-directory ../../TestResults + dotnet test -c ${{ matrix.configuration }}NoWindows --filter TestCategory=RequiresDatabase --logger "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true" --no-build --collect:"XPlat Code Coverage" --settings ../../build/ci.runsettings --results-directory ../../TestResults - name: Store Code Coverage uses: actions/upload-artifact@v3 diff --git a/tests/Tgstation.Server.Tests/Live/TestLiveServer.cs b/tests/Tgstation.Server.Tests/Live/TestLiveServer.cs index 18549fc389..401a17b5f6 100644 --- a/tests/Tgstation.Server.Tests/Live/TestLiveServer.cs +++ b/tests/Tgstation.Server.Tests/Live/TestLiveServer.cs @@ -45,6 +45,7 @@ namespace Tgstation.Server.Tests.Live { [TestClass] [TestCategory("SkipWhenLiveUnitTesting")] + [TestCategory("RequiresDatabase")] public sealed class TestLiveServer { public static readonly Version TestUpdateVersion = new(5, 11, 0); diff --git a/tests/Tgstation.Server.Tests/TestDatabase.cs b/tests/Tgstation.Server.Tests/TestDatabase.cs index 943eed0e4c..7d3a146e26 100644 --- a/tests/Tgstation.Server.Tests/TestDatabase.cs +++ b/tests/Tgstation.Server.Tests/TestDatabase.cs @@ -17,6 +17,7 @@ using Microsoft.Extensions.DependencyInjection; namespace Tgstation.Server.Tests { [TestClass] + [TestCategory("RequiresDatabase")] public sealed class TestDatabase { [TestMethod] diff --git a/tests/Tgstation.Server.Tests/TestRepository.cs b/tests/Tgstation.Server.Tests/TestRepository.cs index 9a8a42c92a..e03fbe984a 100644 --- a/tests/Tgstation.Server.Tests/TestRepository.cs +++ b/tests/Tgstation.Server.Tests/TestRepository.cs @@ -1,4 +1,7 @@ -using System.Threading.Tasks; +using System; +using System.IO; +using System.Threading; +using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -10,7 +13,6 @@ using Tgstation.Server.Host.Components.Repository; using Tgstation.Server.Host.Configuration; using Tgstation.Server.Host.IO; using Tgstation.Server.Host.Jobs; -using Tgstation.Server.Tests.Live; namespace Tgstation.Server.Tests { @@ -20,29 +22,39 @@ namespace Tgstation.Server.Tests [TestMethod] public async Task TestRepoParentLookup() { - using var testingServer = new LiveTestingServer(null, false); - LibGit2Sharp.Repository.Clone("https://github.com/Cyberboss/test", testingServer.Directory); - var libGit2Repo = new LibGit2Sharp.Repository(testingServer.Directory); - using var repo = new Repository( - libGit2Repo, - new LibGit2Commands(), - Mock.Of(), - Mock.Of(), - Mock.Of(), - Mock.Of(), - Mock.Of(), - Mock.Of>(), - new GeneralConfiguration(), - () => { }); + var tempPath = Path.Combine(Path.GetTempPath(), "TGS-Repository-Integration-Test", Guid.NewGuid().ToString()); + Directory.CreateDirectory(tempPath); + try + { + LibGit2Sharp.Repository.Clone("https://github.com/Cyberboss/test", tempPath); + var libGit2Repo = new LibGit2Sharp.Repository(tempPath); + using var repo = new Repository( + libGit2Repo, + new LibGit2Commands(), + Mock.Of(), + Mock.Of(), + Mock.Of(), + Mock.Of(), + Mock.Of(), + Mock.Of>(), + new GeneralConfiguration(), + () => { }); - const string StartSha = "af4da8beb9f9b374b04a3cc4d65acca662e8cc1a"; - await repo.CheckoutObject(StartSha, null, null, true, new JobProgressReporter(Mock.Of>(), null, (stage, progress) => { }), default); - var result = await repo.ShaIsParent("2f8588a3ca0f6b027704a2a04381215619de3412", default); - Assert.IsTrue(result); - Assert.AreEqual(StartSha, repo.Head); - result = await repo.ShaIsParent("f636418bf47d238d33b0e4a34f0072b23a8aad0e", default); - Assert.IsFalse(result); - Assert.AreEqual(StartSha, repo.Head); + const string StartSha = "af4da8beb9f9b374b04a3cc4d65acca662e8cc1a"; + await repo.CheckoutObject(StartSha, null, null, true, new JobProgressReporter(Mock.Of>(), null, (stage, progress) => { }), CancellationToken.None); + var result = await repo.ShaIsParent("2f8588a3ca0f6b027704a2a04381215619de3412", CancellationToken.None); + Assert.IsTrue(result); + Assert.AreEqual(StartSha, repo.Head); + result = await repo.ShaIsParent("f636418bf47d238d33b0e4a34f0072b23a8aad0e", CancellationToken.None); + Assert.IsFalse(result); + Assert.AreEqual(StartSha, repo.Head); + } + finally + { + await new DefaultIOManager().DeleteDirectory( + Path.GetDirectoryName(tempPath), + CancellationToken.None); + } } } }