Skip to content

Conversation

sfoslund
Copy link
Member

@sfoslund sfoslund commented Mar 25, 2021

Not included in this PR:

  • Garbage collection
  • Manifest updates

Testing notes:

  • Any workloads with all packs on https://pkgs.dev.azure.com/azure-public/vside/_packaging/xamarin-impl/nuget/v3/index.json will successfully install (ex macOS, iOS workloads), others won't until we expand the nuget package installer API
  • Example test command: dotnet workload install microsoft-ios-sdk-full --skip-manifest-update, make sure to include skip manifest update flag

@ghost
Copy link

ghost commented Mar 25, 2021

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@sfoslund sfoslund requested review from dsplaisted, joeloff and wli3 March 26, 2021 18:12
@wli3
Copy link

wli3 commented Apr 2, 2021

Sorry please give me sometime to review this change carefully. including run the tests and see the test coverage

Copy link

@wli3 wli3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not done yet

Copy link

@wli3 wli3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally finished a round of check.

Awesome work as always!

@sfoslund sfoslund mentioned this pull request Apr 5, 2021
15 tasks
@sfoslund
Copy link
Member Author

sfoslund commented Apr 6, 2021

@dsplaisted @wli3 @joeloff I think I'm caught up on most of the feedback, is there anything else I should look at?

I'm also consistently getting a test failure that I can't repro anywhere that's caused by a System.UnauthorizedAccessException error when looking at a directory that I lay down in the test. Have any of you seen this kind of things before? https://dev.azure.com/dnceng/public/_build/results?buildId=1074516&view=ms.vss-test-web.build-test-results-tab&runId=32985386&resultId=100738&paneView=debug

@wli3
Copy link

wli3 commented Apr 6, 2021

Let me check again

Copy link
Member

@dsplaisted dsplaisted left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job! Feel free to go ahead and merge and address the feedback separately if that works better for you.

I didn't review the tests yet, I will try to still do that.


using System.Collections.Generic;

namespace Microsoft.DotNet.Workloads.Workload.Install
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are going to want the workload resolver to be able to use the IAL (to check installation records for the current band). So can we factor out most of the workload installation code into a separate library that dotnet and Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver would reference (and would be included as source in the Microsoft.DotNet.MSBuildSdkResolver project)?

@sfoslund
Copy link
Member Author

sfoslund commented Apr 8, 2021

@dsplaisted thanks for the feedback! I think I addressed all of it and there were some significant changes (especially in garbage collection) in the last commit, do you want to take a look before I merge?

The only piece I've left out of this PR is refactoring this into a separate project per this comment. I've added it to #16483 as a follow up task.

@sfoslund
Copy link
Member Author

sfoslund commented Apr 8, 2021

@wli3 I had to add a workaround for testing workload commands when the DEVENABLEWORKLOADCOMMAND environment variable isn't set, is there somewhere you're tracking removing that env var so I can add a note to remove 35900a5 as well?

Comment on lines +42 to +43
installer.InstalledPacks.Count.Should().Be(8);
installer.InstalledPacks.Where(pack => pack.Id.Contains("Android")).Count().Should().Be(8);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest calling Should().BeEquivalentTo() and passing the list of 8 packs that should be installed.

Comment on lines 56 to 71
try
{
installManager.InstallWorkloads(mockWorkloadIds, true);

// Install should have failed
true.Should().BeFalse();
}
catch (Exception e)
{
e.Message.Should().Be("Failing workload: xamarin-android-build");
var expectedPacks = mockWorkloadIds
.SelectMany(workloadId => workloadResolver.GetPacksInWorkload(workloadId.ToString()))
.Select(packId => workloadResolver.TryGetPackInfo(packId));
installer.RolledBackPacks.ShouldBeEquivalentTo(expectedPacks);
installer.WorkloadInstallRecord.Should().BeEmpty();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a try/catch block and a true.Should().BeFalse() assertion, try using Assert.Throws:

Suggested change
try
{
installManager.InstallWorkloads(mockWorkloadIds, true);
// Install should have failed
true.Should().BeFalse();
}
catch (Exception e)
{
e.Message.Should().Be("Failing workload: xamarin-android-build");
var expectedPacks = mockWorkloadIds
.SelectMany(workloadId => workloadResolver.GetPacksInWorkload(workloadId.ToString()))
.Select(packId => workloadResolver.TryGetPackInfo(packId));
installer.RolledBackPacks.ShouldBeEquivalentTo(expectedPacks);
installer.WorkloadInstallRecord.Should().BeEmpty();
}
var exceptionThrown = Assert.Throws<Exception>(() => installManager.InstallWorkloads(mockWorkloadIds, true));
exceptionThrown.Message.Should().Be("Failing workload: xamarin-android-build");
var expectedPacks = mockWorkloadIds
.SelectMany(workloadId => workloadResolver.GetPacksInWorkload(workloadId.ToString()))
.Select(packId => workloadResolver.TryGetPackInfo(packId));
installer.RolledBackPacks.ShouldBeEquivalentTo(expectedPacks);
installer.WorkloadInstallRecord.Should().BeEmpty();

Separately, I think the test should hard-code the expected packs instead of calling into the workload resolver to figure out what packs make up the workload.

}
}

private (string, NetSdkManagedInstaller, INuGetPackageInstaller) GetTestInstaller([CallerMemberName] string identifier = "", bool failingInstaller = false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use testName here instead of identifier. The identifier is generally used to disambiguate between multiple instances of the same theory. As is, there's a mismatch on the next line where the identifier is being passed in as the testName parameter to CreateTestDirectory.

}

[Fact]
public void GivenManagedInstallItCanGetFeatureBands()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think GetFeatureBandsWithInstallationRecords should be changed so it only returns bands where there are actually workload installation records. So this test should be updated to account for that, and to test both empty and non-empty InstalledWorkloads directories.

}

[Fact]
public void GivenManagedInstallItCanGetInstalledWorkloads()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this test I'd suggest writing some different workloads for a different feature band to verify it doesn't pick those up.

}

[Fact]
public void GivenManagedInstallItDetectInstalledPacks()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar nit

Suggested change
public void GivenManagedInstallItDetectInstalledPacks()
public void GivenManagedInstallItDetectsInstalledPacks()


installer.InstallWorkloadPack(packInfo, new SdkFeatureBand(version));

_reporter.Lines.Should().Contain(string.Format(LocalizableStrings.WorkloadPackAlreadyInstalledMessage, packInfo.Id, packInfo.Version));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of (or in addition to) verifying the message, could this test check that the NuGet package installer was never called to download the package?

installer.InstallWorkloadPack(packInfo, new SdkFeatureBand(version));

// Install should have failed
true.Should().BeFalse();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switch try/catch and true.Should().BeFalse() for Assert.Throws.

}

[Fact]
public void GivenManagedInstallItCanRollBackInstallFailures()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we have coverage of what happens when multiple packs are supposed to be installed, and some install successfully but then one fails and they all need to be rolled back?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what this test covers: https://github.com/dotnet/sdk/pull/16530/files#diff-c8bc89094b206b506f35f0cb9ac6e55591ae2468130efe0a19dab1810c0f0c1cR52, the first pack installs successfully, the second fails, and they are both rolled back.

}

[Fact]
public void GivenManagedInstallItDoesNotRemovePacksWithInstallRecords()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add some packs to this test that aren't part of the xamarin-android-build workload and verify that they get garbage collected?

@sfoslund
Copy link
Member Author

sfoslund commented Apr 9, 2021

Thanks for the feedback, I'll address it in a follow up PR

@sfoslund sfoslund merged commit 023ed10 into dotnet:main Apr 9, 2021
@sfoslund sfoslund deleted the WorkloadInstall branch April 9, 2021 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants