diff --git a/.github/workflows/ci-suite.yml b/.github/workflows/ci-suite.yml index 1d7fbc8837..0e81e3e7f6 100644 --- a/.github/workflows/ci-suite.yml +++ b/.github/workflows/ci-suite.yml @@ -246,21 +246,6 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Set TGS_TEST_PULL_REQUEST_NUMBER - if: ${{ github.event_name == 'pull_request' }} - run: echo "TGS_TEST_PULL_REQUEST_NUMBER=${{ github.event.number }}" >> $Env:GITHUB_ENV - - - name: Set TGS_GITHUB_REF for PR - if: ${{ github.event_name == 'pull_request' }} - run: echo "TGS_GITHUB_REF=${{ github.base_ref }}" >> $Env:GITHUB_ENV - - - name: Set TGS_GITHUB_REF for push - if: ${{ github.event_name == 'push' }} - shell: bash - run: | - TEMP_GITHUB_REF="${{ github.event.ref }}" - echo "TGS_GITHUB_REF=${TEMP_GITHUB_REF##*/}" >> $GITHUB_ENV - - name: Run Integration Test run: | cd tests/Tgstation.Server.Tests @@ -395,21 +380,6 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Set TGS_TEST_PULL_REQUEST_NUMBER - if: ${{ github.event_name == 'pull_request' }} - run: echo "TGS_TEST_PULL_REQUEST_NUMBER=${{ github.event.number }}" >> $GITHUB_ENV - - - name: Set TGS_GITHUB_REF for PR - if: ${{ github.event_name == 'pull_request' }} - run: echo "TGS_GITHUB_REF=${{ github.base_ref }}" >> $GITHUB_ENV - - - name: Set TGS_GITHUB_REF for push - if: ${{ github.event_name == 'push' }} - shell: bash - run: | - TEMP_GITHUB_REF="${{ github.event.ref }}" - echo "TGS_GITHUB_REF=${TEMP_GITHUB_REF##*/}" >> $GITHUB_ENV - - name: Run Integration Test run: | cd tests/Tgstation.Server.Tests diff --git a/tests/Tgstation.Server.Tests/Instance/ConfigurationTest.cs b/tests/Tgstation.Server.Tests/Instance/ConfigurationTest.cs index 05227e7328..cf61a02737 100644 --- a/tests/Tgstation.Server.Tests/Instance/ConfigurationTest.cs +++ b/tests/Tgstation.Server.Tests/Instance/ConfigurationTest.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Linq; using System.Net.Http; using System.Net.Mime; using System.Reflection; @@ -13,6 +14,8 @@ using Tgstation.Server.Api.Models; using Tgstation.Server.Api.Models.Request; using Tgstation.Server.Client; using Tgstation.Server.Client.Components; +using Tgstation.Server.Host.IO; +using Tgstation.Server.Host.System; namespace Tgstation.Server.Tests.Instance { @@ -35,7 +38,7 @@ namespace Tgstation.Server.Tests.Instance return result; } - async Task TestDeleteDirectory(CancellationToken cancellationToken) + async Task TestUploadDownloadAndDeleteDirectory(CancellationToken cancellationToken) { //try to delete non-existent var TestDir = new ConfigurationFileRequest @@ -97,9 +100,29 @@ namespace Tgstation.Server.Tests.Instance await configurationClient.CreateDirectory(staticDir, cancellationToken); } - public async Task Run(CancellationToken cancellationToken) + Task SetupDMApiTests(CancellationToken cancellationToken) { - await TestDeleteDirectory(cancellationToken); + // just use an I/O manager here + var ioManager = new DefaultIOManager(new AssemblyInformationProvider()); + return Task.WhenAll( + ioManager.CopyDirectory( + "../../../../DMAPI", + ioManager.ConcatPath(instance.Path, "Repository", "tests", "DMAPI"), + Enumerable.Empty(), + null, + cancellationToken), + ioManager.CopyDirectory( + "../../../../../src/DMAPI", + ioManager.ConcatPath(instance.Path, "Repository", "src", "DMAPI"), + Enumerable.Empty(), + null, + cancellationToken) + ); + } + + public Task RunPreWatchdog(CancellationToken cancellationToken) + { + return Task.WhenAll(TestUploadDownloadAndDeleteDirectory(cancellationToken), SetupDMApiTests(cancellationToken)); } } } diff --git a/tests/Tgstation.Server.Tests/Instance/DeploymentTest.cs b/tests/Tgstation.Server.Tests/Instance/DeploymentTest.cs index 37570083e9..6de276f66e 100644 --- a/tests/Tgstation.Server.Tests/Instance/DeploymentTest.cs +++ b/tests/Tgstation.Server.Tests/Instance/DeploymentTest.cs @@ -18,6 +18,8 @@ namespace Tgstation.Server.Tests.Instance readonly IDreamDaemonClient dreamDaemonClient; readonly IInstanceClient instanceClient; + Task vpTest; + public DeploymentTest(IInstanceClient instanceClient, IJobsClient jobsClient) : base(jobsClient) { this.instanceClient = instanceClient ?? throw new ArgumentException(nameof(instanceClient)); @@ -25,9 +27,10 @@ namespace Tgstation.Server.Tests.Instance this.dreamDaemonClient = instanceClient.DreamDaemon; } - public async Task Run(Task repositoryTask, CancellationToken cancellationToken) + public async Task RunPreRepoClone(CancellationToken cancellationToken) { - var vpTest = TestVisibilityPermission(cancellationToken); + Assert.IsNull(vpTest); + vpTest = TestVisibilityPermission(cancellationToken); var deployJob = await dreamMakerClient.Compile(cancellationToken); deployJob = await WaitForJob(deployJob, 30, true, null, cancellationToken); Assert.IsTrue(deployJob.ErrorCode == ErrorCode.RepoCloning || deployJob.ErrorCode == ErrorCode.RepoMissing); @@ -35,9 +38,11 @@ namespace Tgstation.Server.Tests.Instance var dmSettings = await dreamMakerClient.Read(cancellationToken); Assert.AreEqual(true, dmSettings.RequireDMApiValidation); Assert.AreEqual(null, dmSettings.ProjectName); + } - await repositoryTask; - + public async Task RunPostRepoClone(CancellationToken cancellationToken) + { + Assert.IsNotNull(vpTest); // by alphabetization rules, it should discover api_free here if (!new PlatformIdentifier().IsWindows) { @@ -76,7 +81,7 @@ namespace Tgstation.Server.Tests.Instance ApiValidationPort = IntegrationTest.DDPort }, cancellationToken), ErrorCode.PortNotAvailable); - deployJob = await dreamMakerClient.Compile(cancellationToken); + var deployJob = await dreamMakerClient.Compile(cancellationToken); await WaitForJob(deployJob, 40, true, ErrorCode.DreamMakerNeverValidated, cancellationToken); const string FailProject = "tests/DMAPI/BuildFail/build_fail"; diff --git a/tests/Tgstation.Server.Tests/Instance/InstanceTest.cs b/tests/Tgstation.Server.Tests/Instance/InstanceTest.cs index 862b65ffc8..fa9c1664d3 100644 --- a/tests/Tgstation.Server.Tests/Instance/InstanceTest.cs +++ b/tests/Tgstation.Server.Tests/Instance/InstanceTest.cs @@ -31,15 +31,20 @@ namespace Tgstation.Server.Tests.Instance var repoTest = new RepositoryTest(instanceClient.Repository, instanceClient.Jobs); var dmTest = new DeploymentTest(instanceClient, instanceClient.Jobs); - var byondTests = byondTest.Run(cancellationToken); - var repoTests = repoTest.RunPreWatchdog(cancellationToken); - var chatTests = chatTest.RunPreWatchdog(cancellationToken); - await byondTests; - await dmTest.Run(repoTests, cancellationToken); + var byondTask = byondTest.Run(cancellationToken); + var chatTask = chatTest.RunPreWatchdog(cancellationToken); + + var repoLongJob = repoTest.RunLongClone(cancellationToken); + + await dmTest.RunPreRepoClone(cancellationToken); + await repoTest.AbortLongCloneAndCloneSomethingQuick(await repoLongJob, cancellationToken); + await configTest.RunPreWatchdog(cancellationToken); + var dmTask = dmTest.RunPostRepoClone(cancellationToken); + + await byondTask; + await chatTask; + await dmTask; - await configTest.Run(cancellationToken); - await chatTests; - await repoTests; await new WatchdogTest(instanceClient, instanceManager, serverPort).Run(cancellationToken); } } diff --git a/tests/Tgstation.Server.Tests/Instance/RepositoryTest.cs b/tests/Tgstation.Server.Tests/Instance/RepositoryTest.cs index 74ba887424..9e6cc18466 100644 --- a/tests/Tgstation.Server.Tests/Instance/RepositoryTest.cs +++ b/tests/Tgstation.Server.Tests/Instance/RepositoryTest.cs @@ -1,4 +1,4 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Collections.Generic; using System.Linq; @@ -23,22 +23,9 @@ namespace Tgstation.Server.Tests.Instance this.repositoryClient = repositoryClient ?? throw new ArgumentNullException(nameof(repositoryClient)); } - public async Task RunPreWatchdog(CancellationToken cancellationToken) + public async Task RunLongClone(CancellationToken cancellationToken) { - const string TestRefEnvVar = "TGS_GITHUB_REF"; - var envVar = Environment.GetEnvironmentVariable(TestRefEnvVar); - string workingBranch = null; - if (!String.IsNullOrWhiteSpace(envVar)) - { - workingBranch = envVar; - Console.WriteLine($"TEST: Set working branch to '{workingBranch}' from env var '{TestRefEnvVar}'"); - } - - if (workingBranch == null) - { - workingBranch = "master"; - Console.WriteLine($"TEST: Set working branch to default '{workingBranch}'"); - } + var workingBranch = "master"; var initalRepo = await repositoryClient.Read(cancellationToken); Assert.IsNotNull(initalRepo); @@ -47,7 +34,7 @@ namespace Tgstation.Server.Tests.Instance Assert.IsNull(initalRepo.RevisionInformation); Assert.IsNull(initalRepo.ActiveJob); - const string Origin = "https://github.com/tgstation/tgstation-server"; + const string Origin = "https://github.com/tgstation/tgstation"; var cloneRequest = new RepositoryCreateRequest { Origin = new Uri(Origin), @@ -62,16 +49,8 @@ namespace Tgstation.Server.Tests.Instance Assert.IsNull(clone.RevisionInformation); Assert.IsNotNull(clone.ActiveJob); - await WaitForJobProgressThenCancel(clone.ActiveJob, 40, cancellationToken); - - var secondRead = await repositoryClient.Read(cancellationToken); - Assert.IsNotNull(secondRead); - Assert.IsNull(secondRead.ActiveJob); - - clone = await repositoryClient.Clone(cloneRequest, cancellationToken); - // throwing this small jobs consistency test in here - await Task.Delay(TimeSpan.FromSeconds(20), cancellationToken); + await Task.Delay(TimeSpan.FromSeconds(10), cancellationToken); var activeJobs = await JobsClient.ListActive(null, cancellationToken); var allJobs = await JobsClient.List(null, cancellationToken); @@ -80,11 +59,30 @@ namespace Tgstation.Server.Tests.Instance Assert.IsTrue(activeJobs.First(x => x.Id == clone.ActiveJob.Id).Progress.HasValue); Assert.IsTrue(allJobs.First(x => x.Id == clone.ActiveJob.Id).Progress.HasValue); - await WaitForJob(clone.ActiveJob, 9000, false, null, cancellationToken); + return clone.ActiveJob; + } + + public async Task AbortLongCloneAndCloneSomethingQuick(JobResponse longCloneJob, CancellationToken cancellationToken) + { + await WaitForJobProgressThenCancel(longCloneJob, 40, cancellationToken); + + var secondRead = await repositoryClient.Read(cancellationToken); + Assert.IsNotNull(secondRead); + Assert.IsNull(secondRead.ActiveJob); + + const string Origin = "https://github.com/tgstation/common_core"; + var cloneRequest = new RepositoryCreateRequest + { + Origin = new Uri(Origin), + }; + + var clone = await repositoryClient.Clone(cloneRequest, cancellationToken); + + await WaitForJob(clone.ActiveJob, 60, false, null, cancellationToken); var readAfterClone = await repositoryClient.Read(cancellationToken); Assert.AreEqual(cloneRequest.Origin, readAfterClone.Origin); - Assert.AreEqual(workingBranch, readAfterClone.Reference); + Assert.AreEqual("master", readAfterClone.Reference); Assert.IsNotNull(readAfterClone.RevisionInformation); Assert.IsNotNull(readAfterClone.RevisionInformation.ActiveTestMerges); Assert.AreEqual(0, readAfterClone.RevisionInformation.ActiveTestMerges.Count); @@ -97,12 +95,9 @@ namespace Tgstation.Server.Tests.Instance Assert.AreEqual(readAfterClone.RevisionInformation.CommitSha, readAfterClone.RevisionInformation.OriginCommitSha); Assert.AreNotEqual(default, readAfterClone.RevisionInformation.Timestamp); - // checkout V3 and back - var updated = await Checkout(new RepositoryUpdateRequest { Reference = "V3" }, false, true, cancellationToken); - // Specific SHA - await ApiAssert.ThrowsException(() => Checkout(new RepositoryUpdateRequest { Reference = "V3", CheckoutSha = "f43f5bd" }, false, false, cancellationToken), ErrorCode.RepoMismatchShaAndReference); - updated = await Checkout(new RepositoryUpdateRequest { CheckoutSha = "f43f5bd" }, false, false, cancellationToken); + await ApiAssert.ThrowsException(() => Checkout(new RepositoryUpdateRequest { Reference = "master", CheckoutSha = "286bb75" }, false, false, cancellationToken), ErrorCode.RepoMismatchShaAndReference); + var updated = await Checkout(new RepositoryUpdateRequest { CheckoutSha = "286bb75" }, false, false, cancellationToken); // Fake SHA updated = await Checkout(new RepositoryUpdateRequest { CheckoutSha = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, true, false, cancellationToken); @@ -111,22 +106,9 @@ namespace Tgstation.Server.Tests.Instance updated = await Checkout(new RepositoryUpdateRequest { Reference = "TgsIntegrationTestFakeBranchNeverNameABranchThis" }, true, true, cancellationToken); // Back - updated = await Checkout(new RepositoryUpdateRequest { Reference = workingBranch }, false, true, cancellationToken); + updated = await Checkout(new RepositoryUpdateRequest { Reference = "master" }, false, true, cancellationToken); - var testPRString = Environment.GetEnvironmentVariable("TGS_TEST_PULL_REQUEST_NUMBER"); - if (String.IsNullOrWhiteSpace(testPRString)) - testPRString = Environment.GetEnvironmentVariable("APPVEYOR_PULL_REQUEST_NUMBER"); - if (String.IsNullOrWhiteSpace(testPRString)) - testPRString = Environment.GetEnvironmentVariable("TRAVIS_PULL_REQUEST"); - - if (String.IsNullOrWhiteSpace(testPRString)) - if (workingBranch == "dev") - testPRString = "957"; - else - testPRString = "958"; - - if (!int.TryParse(testPRString, out var prNumber)) - Assert.Inconclusive($"Invalid PR #: {testPRString}"); + var prNumber = 37; await TestMergeTests(updated, prNumber, cancellationToken); } @@ -182,7 +164,7 @@ namespace Tgstation.Server.Tests.Instance Assert.IsNotNull(withMerge.RevisionInformation.PrimaryTestMerge.TitleAtMerge); Assert.IsNotNull(withMerge.RevisionInformation.PrimaryTestMerge.BodyAtMerge); if (withMerge.RevisionInformation.PrimaryTestMerge.Url != "GITHUB API ERROR: RATE LIMITED") - Assert.AreEqual($"https://github.com/tgstation/tgstation-server/pull/{prNumber}", withMerge.RevisionInformation.PrimaryTestMerge.Url); + Assert.AreEqual($"https://github.com/tgstation/common_core/pull/{prNumber}", withMerge.RevisionInformation.PrimaryTestMerge.Url); Assert.AreEqual(orignCommit, withMerge.RevisionInformation.OriginCommitSha); Assert.AreNotEqual(orignCommit, withMerge.RevisionInformation.CommitSha);