Skip to content

Commit

Permalink
Fix clean-up after the ArcadeSDK E2E test (#4242)
Browse files Browse the repository at this point in the history
  • Loading branch information
premun authored Dec 12, 2024
1 parent a7d4c92 commit e62722e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1021,12 +1021,12 @@ protected static async Task<bool> ValidateGithubMaestroCheckRunsSuccessful(strin

protected static string GetTestChannelName([CallerMemberName] string testName = "")
{
return $"c{testName}_{Guid.NewGuid().ToString().Substring(0, 16)}";
return $"Test {testName} {Guid.NewGuid().ToString().Substring(0, 16)}";
}

protected static string GetTestBranchName([CallerMemberName] string testName = "")
{
return $"b{testName}_{Guid.NewGuid().ToString().Substring(0, 16)}";
return $"test/{testName}/{Guid.NewGuid().ToString().Substring(0, 16)}";
}

protected string GetUniqueAssetName(string packageName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ internal class ScenarioTests_SdkUpdate : ScenarioTestBase
[TestCase(true)]
public async Task ArcadeSdkUpdate_E2E(bool targetAzDO)
{
var testChannelName = "Test Channel " + _random.Next(int.MaxValue);
const string sourceOrg = "maestro-auth-test";
var testChannelName = GetTestChannelName();
var targetBranch = GetTestBranchName();

const string sourceRepo = "arcade";
const string sourceRepoUri = $"https://github.com/{sourceOrg}/{sourceRepo}";
const string sourceRepoUri = $"https://github.com/{TestRepository.TestOrg}/{sourceRepo}";
const string sourceBranch = "dependencyflow-tests";
const string sourceCommit = "f3d51d2c9af2a3eb046fa54c5acdef9fb37db172";
const string newArcadeSdkVersion = "2.1.0";
var sourceBuildNumber = _random.Next(int.MaxValue).ToString();

Expand All @@ -37,21 +37,19 @@ public async Task ArcadeSdkUpdate_E2E(bool targetAzDO)
Version = newArcadeSdkVersion
}
];
var targetRepo = "maestro-test2";
var targetBranch = "test/" + _random.Next(int.MaxValue).ToString();

await using AsyncDisposableValue<string> channel =
await CreateTestChannelAsync(testChannelName);
await using AsyncDisposableValue<string> sub =
await CreateSubscriptionAsync(testChannelName, sourceRepo, targetRepo, targetBranch, "none", sourceOrg: sourceOrg, targetIsAzDo: targetAzDO);
await CreateSubscriptionAsync(testChannelName, sourceRepo, TestRepository.TestRepo2Name, targetBranch, "none", TestRepository.TestOrg, targetIsAzDo: targetAzDO);
Build build =
await CreateBuildAsync(GetRepoUrl(sourceOrg, sourceRepo), sourceBranch, sourceCommit, sourceBuildNumber, sourceAssets);
await CreateBuildAsync(GetRepoUrl(TestRepository.TestOrg, sourceRepo), sourceBranch, TestRepository.ArcadeTestRepoCommit, sourceBuildNumber, sourceAssets);

await using IAsyncDisposable _ = await AddBuildToChannelAsync(build.Id, testChannelName);

using TemporaryDirectory repo = targetAzDO
? await CloneAzDoRepositoryAsync(targetRepo)
: await CloneRepositoryAsync(targetRepo);
? await CloneAzDoRepositoryAsync(TestRepository.TestRepo2Name)
: await CloneRepositoryAsync(TestRepository.TestRepo2Name);

using (ChangeDirectory(repo.Directory))
{
Expand All @@ -61,26 +59,27 @@ await RunDarcAsync("add-dependency",
"--type", "toolset",
"--repo", sourceRepoUri);
await RunGitAsync("commit", "-am", "Add dependencies.");
await using IAsyncDisposable ___ = await PushGitBranchAsync("origin", targetBranch);
await using IAsyncDisposable __ = await PushGitBranchAsync("origin", targetBranch);
await TriggerSubscriptionAsync(sub.Value);

var expectedTitle = $"[{targetBranch}] Update dependencies from {sourceOrg}/{sourceRepo}";
var expectedTitle = $"[{targetBranch}] Update dependencies from {TestRepository.TestOrg}/{sourceRepo}";
DependencyDetail expectedDependency = new()
{
Name = DependencyFileManager.ArcadeSdkPackageName,
Version = newArcadeSdkVersion,
RepoUri = sourceRepoUri,
Commit = sourceCommit,
Commit = TestRepository.ArcadeTestRepoCommit,
Type = DependencyType.Toolset,
Pinned = false,
};

string prHead;
IAsyncDisposable cleanUp;
if (targetAzDO)
{
prHead = await CheckAzDoPullRequest(
expectedTitle,
targetRepo,
TestRepository.TestRepo2Name,
targetBranch,
[expectedDependency],
repo.Directory,
Expand All @@ -89,44 +88,54 @@ await RunDarcAsync("add-dependency",
cleanUp: false,
expectedFeeds: null,
notExpectedFeeds: null);

cleanUp = AsyncDisposable.Create(async () =>
{
await TestParameters.AzDoClient.DeleteBranchAsync(GetAzDoRepoUrl(TestRepository.TestRepo2Name), prHead);
});
}
else
{
Octokit.PullRequest pr = await WaitForPullRequestAsync(targetRepo, targetBranch);
Octokit.PullRequest pr = await WaitForPullRequestAsync(TestRepository.TestRepo2Name, targetBranch);
pr.Title.Should().BeEquivalentTo(expectedTitle);
prHead = pr.Head.Ref;

cleanUp = CleanUpPullRequestAfter(TestRepository.TestOrg, TestRepository.TestRepo2Name, pr);
}

await CheckoutRemoteRefAsync(prHead);

var dependencies = await RunDarcAsync("get-dependencies");
var dependencyLines = dependencies.Split(['\n', '\r'], StringSplitOptions.RemoveEmptyEntries);
dependencyLines.Should().BeEquivalentTo(
[
$"Name: {DependencyFileManager.ArcadeSdkPackageName}",
$"Version: {newArcadeSdkVersion}",
$"Repo: {sourceRepoUri}",
$"Commit: {sourceCommit}",
"Type: Toolset",
"Pinned: False",
]);

using TemporaryDirectory arcadeRepo = await CloneRepositoryAsync(sourceOrg, sourceRepo);
using (ChangeDirectory(arcadeRepo.Directory))
await using (cleanUp)
{
await CheckoutRemoteRefAsync(sourceCommit);
await CheckoutRemoteRefAsync(prHead);

var dependencies = await RunDarcAsync("get-dependencies");
var dependencyLines = dependencies.Split(['\n', '\r'], StringSplitOptions.RemoveEmptyEntries);
dependencyLines.Should().BeEquivalentTo(
[
$"Name: {DependencyFileManager.ArcadeSdkPackageName}",
$"Version: {newArcadeSdkVersion}",
$"Repo: {sourceRepoUri}",
$"Commit: {TestRepository.ArcadeTestRepoCommit}",
"Type: Toolset",
"Pinned: False",
]);

using TemporaryDirectory arcadeRepo = await CloneRepositoryAsync(TestRepository.TestOrg, sourceRepo);
using (ChangeDirectory(arcadeRepo.Directory))
{
await CheckoutRemoteRefAsync(TestRepository.ArcadeTestRepoCommit);
}

var arcadeFiles = Directory.EnumerateFileSystemEntries(Path.Join(arcadeRepo.Directory, "eng", "common"),
"*", SearchOption.AllDirectories)
.Select(s => s.Substring(arcadeRepo.Directory.Length))
.ToHashSet();
var repoFiles = Directory.EnumerateFileSystemEntries(Path.Join(repo.Directory, "eng", "common"),
"*", SearchOption.AllDirectories)
.Select(s => s.Substring(repo.Directory.Length))
.ToHashSet();

arcadeFiles.Should().BeEquivalentTo(repoFiles);
}

var arcadeFiles = Directory.EnumerateFileSystemEntries(Path.Join(arcadeRepo.Directory, "eng", "common"),
"*", SearchOption.AllDirectories)
.Select(s => s.Substring(arcadeRepo.Directory.Length))
.ToHashSet();
var repoFiles = Directory.EnumerateFileSystemEntries(Path.Join(repo.Directory, "eng", "common"), "*",
SearchOption.AllDirectories)
.Select(s => s.Substring(repo.Directory.Length))
.ToHashSet();

arcadeFiles.Should().BeEquivalentTo(repoFiles);
}
}
}
17 changes: 9 additions & 8 deletions test/ProductConstructionService.ScenarioTests/TestRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ namespace ProductConstructionService.ScenarioTests;

internal class TestRepository
{
internal static string TestRepo1Name => "maestro-test1";
internal static string TestRepo2Name => "maestro-test2";
internal static string TestRepo3Name => "maestro-test3";
internal static string VmrTestRepoName => "maestro-test-vmr";
internal static string SourceBranch => "master";
internal const string TestOrg = "maestro-auth-test";
internal const string TestRepo1Name = "maestro-test1";
internal const string TestRepo2Name = "maestro-test2";
internal const string TestRepo3Name = "maestro-test3";
internal const string VmrTestRepoName = "maestro-test-vmr";
internal const string SourceBranch = "master";

// This branch and commit data is special for the coherency test
// It's required to make sure that the dependency tree is set up correctly in the repo without conflicting with other test cases
internal static string CoherencySourceBranch => "coherency-tree";
internal static string CoherencyTestRepo1Commit => "cc1a27107a1f4c4bc5e2f796c5ef346f60abb404";
internal static string CoherencyTestRepo2Commit => "8460158878d4b7568f55d27960d4453877523ea6";
internal const string CoherencyTestRepo1Commit = "cc1a27107a1f4c4bc5e2f796c5ef346f60abb404";
internal const string CoherencyTestRepo2Commit = "8460158878d4b7568f55d27960d4453877523ea6";
internal const string ArcadeTestRepoCommit = "f3d51d2c9af2a3eb046fa54c5acdef9fb37db172";
}

0 comments on commit e62722e

Please sign in to comment.