public async Task RunPreWatchdog(CancellationToken cancellationToken) { const string TestRefEnvVar = "TGS4_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 initalRepo = await repositoryClient.Read(cancellationToken); Assert.IsNotNull(initalRepo); Assert.IsNull(initalRepo.Origin); Assert.IsNull(initalRepo.Reference); Assert.IsNull(initalRepo.RevisionInformation); Assert.IsNull(initalRepo.ActiveJob); const string Origin = "https://github.com/tgstation/tgstation-server"; var cloneRequest = new RepositoryCreateRequest { Origin = new Uri(Origin), Reference = workingBranch, }; var clone = await repositoryClient.Clone(cloneRequest, cancellationToken).ConfigureAwait(false); await ApiAssert.ThrowsException <ConflictException>(() => repositoryClient.Read(cancellationToken), ErrorCode.RepoCloning); Assert.IsNotNull(clone); Assert.AreEqual(cloneRequest.Origin, clone.Origin); Assert.AreEqual(workingBranch, clone.Reference); Assert.IsNull(clone.RevisionInformation); Assert.IsNotNull(clone.ActiveJob); await WaitForJobProgressThenCancel(clone.ActiveJob, 20, cancellationToken).ConfigureAwait(false); var secondRead = await repositoryClient.Read(cancellationToken).ConfigureAwait(false); Assert.IsNotNull(secondRead); Assert.IsNull(secondRead.ActiveJob); clone = await repositoryClient.Clone(cloneRequest, cancellationToken).ConfigureAwait(false); // throwing this small jobs consistency test in here await Task.Delay(TimeSpan.FromSeconds(20), cancellationToken).ConfigureAwait(false); var activeJobs = await JobsClient.ListActive(null, cancellationToken); var allJobs = await JobsClient.List(null, cancellationToken).ConfigureAwait(false); Assert.IsTrue(activeJobs.Any(x => x.Id == clone.ActiveJob.Id)); Assert.IsTrue(allJobs.Any(x => x.Id == clone.ActiveJob.Id)); 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).ConfigureAwait(false); var readAfterClone = await repositoryClient.Read(cancellationToken); Assert.AreEqual(cloneRequest.Origin, readAfterClone.Origin); Assert.AreEqual(workingBranch, readAfterClone.Reference); Assert.IsNotNull(readAfterClone.RevisionInformation); Assert.IsNotNull(readAfterClone.RevisionInformation.ActiveTestMerges); Assert.AreEqual(0, readAfterClone.RevisionInformation.ActiveTestMerges.Count); Assert.IsNotNull(readAfterClone.RevisionInformation.CommitSha); Assert.IsNotNull(readAfterClone.RevisionInformation.OriginCommitSha); Assert.IsNotNull(readAfterClone.RevisionInformation.CompileJobs); Assert.AreEqual(0, readAfterClone.RevisionInformation.CompileJobs.Count); Assert.IsNotNull(readAfterClone.RevisionInformation.OriginCommitSha); Assert.IsNull(readAfterClone.RevisionInformation.PrimaryTestMerge); Assert.AreEqual(readAfterClone.RevisionInformation.CommitSha, readAfterClone.RevisionInformation.OriginCommitSha); Assert.AreNotEqual(default, readAfterClone.RevisionInformation.Timestamp);