Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#508) Fix multiple packages being uninstall fails if one is a dependency #3142

Merged
3 changes: 2 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_prefer_extended_property_pattern = true:suggestion
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_style_var_elsewhere = false:suggestion
csharp_style_var_elsewhere = true:suggestion

[*.{cs,vb}]
#### Naming styles ####

Expand Down
12 changes: 6 additions & 6 deletions src/chocolatey.tests.integration/scenarios/InfoScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ public void Should_log_package_count_as_warning()

public class When_searching_for_non_normalized_exact_package : CommandScenariosBase
{
private string NonNormalizedVersion = "004.0.01.0";
private string NormalizedVersion = "4.0.1";
private const string NonNormalizedVersion = "004.0.01.0";
private const string NormalizedVersion = "4.0.1";

public override void Context()
{
Expand Down Expand Up @@ -226,8 +226,8 @@ public void Should_log_package_count_as_warning()

public class When_searching_for_non_normalized_exact_package_with_version_specified : CommandScenariosBase
{
private string NonNormalizedVersion = "004.0.01.0";
private string NormalizedVersion = "4.0.1";
private const string NonNormalizedVersion = "004.0.01.0";
private const string NormalizedVersion = "4.0.1";

public override void Context()
{
Expand Down Expand Up @@ -269,8 +269,8 @@ public void Should_log_package_count_as_warning()

public class When_searching_for_non_normalized_exact_package_with_non_normalized_version_specified : CommandScenariosBase
{
private string NonNormalizedVersion = "004.0.01.0";
private string NormalizedVersion = "4.0.1";
private const string NonNormalizedVersion = "004.0.01.0";
private const string NormalizedVersion = "4.0.1";

public override void Context()
{
Expand Down
18 changes: 14 additions & 4 deletions src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,20 @@ public void Should_uninstall_the_package_from_the_lib_directory()
DirectoryAssert.DoesNotExist(packageDir);
}

[Fact]
[Pending("Does not work under .Net 4.8, See issue #2690")]
[Broken]
public void Should_not_be_able_delete_the_rollback()
// Locking is inconsistent between client and server operating systems in .NET 4.8.
// On a server, if a file is Read and delete locked it can't be deleted, but on client systems it can.
[Fact, Platform(Exclude = "WindowsServer10")]
public void Should_have_deleted_the_rollback()
{
var packageDir = Path.Combine(Scenario.get_top_level(), "lib-bkp", Configuration.PackageNames);

DirectoryAssert.DoesNotExist(packageDir);
}

// Locking is inconsistent between client and server operating systems in .NET 4.8.
// On a server, if a file is Read and delete locked it can't be deleted, but on client systems it can.
[Fact, Platform("WindowsServer10")]
public void Should_not_have_deleted_the_rollback_on_server()
{
var packageDir = Path.Combine(Scenario.get_top_level(), "lib-bkp", Configuration.PackageNames);

Expand Down
62 changes: 36 additions & 26 deletions src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1932,20 +1932,20 @@ public class When_upgrading_a_package_with_a_read_and_delete_share_locked_file :
{
private PackageResult _packageResult;

private FileStream fileStream;
private FileStream _fileStream;

public override void Context()
{
base.Context();
var fileToOpen = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, "tools", "chocolateyInstall.ps1");
fileStream = new FileStream(fileToOpen, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read | FileShare.Delete);
_fileStream = new FileStream(fileToOpen, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read | FileShare.Delete);
}

public override void AfterObservations()
{
base.AfterObservations();
fileStream.Close();
fileStream.Dispose();
_fileStream.Close();
_fileStream.Dispose();
}

public override void Because()
Expand Down Expand Up @@ -1978,10 +1978,20 @@ public void Should_upgrade_the_package()
}
}

[Fact]
[Pending("Does not work under .Net 4.8, See issue #2690")]
[Broken]
public void Should_not_be_able_delete_the_rollback()
// Locking is inconsistent between client and server operating systems in .NET 4.8.
// On a server, if a file is Read and delete locked it can't be deleted, but on client systems it can.
[Fact, Platform(Exclude = "WindowsServer10")]
public void Should_have_deleted_the_rollback()
{
var packageDir = Path.Combine(Scenario.get_top_level(), "lib-bkp", Configuration.PackageNames);

DirectoryAssert.DoesNotExist(packageDir);
}

// Locking is inconsistent between client and server operating systems in .NET 4.8.
// On a server, if a file is Read and delete locked it can't be deleted, but on client systems it can.
[Fact, Platform("WindowsServer10")]
public void Should_not_have_deleted_the_rollback_on_server()
{
var packageDir = Path.Combine(Scenario.get_top_level(), "lib-bkp", Configuration.PackageNames);

Expand Down Expand Up @@ -2045,20 +2055,20 @@ public class When_upgrading_a_package_with_an_exclusively_locked_file : Scenario
{
private PackageResult _packageResult;

private FileStream fileStream;
private FileStream _fileStream;

public override void Context()
{
base.Context();
var fileToOpen = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, "tools", "chocolateyInstall.ps1");
fileStream = new FileStream(fileToOpen, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
_fileStream = new FileStream(fileToOpen, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
}

public override void AfterObservations()
{
base.AfterObservations();
fileStream.Close();
fileStream.Dispose();
_fileStream.Close();
_fileStream.Dispose();
}

public override void Because()
Expand Down Expand Up @@ -2306,7 +2316,7 @@ public void Should_match_the_upgrade_version_of_one_dot_one_dot_zero()

public class When_upgrading_a_package_that_does_not_exist : ScenariosBase
{
private PackageResult packageResult;
private PackageResult _packageResult;

public override void Context()
{
Expand All @@ -2317,7 +2327,7 @@ public override void Context()
public override void Because()
{
Results = Service.Upgrade(Configuration);
packageResult = Results.FirstOrDefault().Value;
_packageResult = Results.FirstOrDefault().Value;
}

[Fact]
Expand Down Expand Up @@ -2355,26 +2365,26 @@ public void Should_contain_a_message_that_no_packages_were_upgraded()
[Fact]
public void Should_not_have_a_successful_package_result()
{
packageResult.Success.ShouldBeFalse();
_packageResult.Success.ShouldBeFalse();
}

[Fact]
public void Should_not_have_inconclusive_package_result()
{
packageResult.Inconclusive.ShouldBeFalse();
_packageResult.Inconclusive.ShouldBeFalse();
}

[Fact]
public void Should_not_have_warning_package_result()
{
packageResult.Warning.ShouldBeFalse();
_packageResult.Warning.ShouldBeFalse();
}

[Fact]
public void Should_have_an_error_package_result()
{
bool errorFound = false;
foreach (var message in packageResult.Messages)
foreach (var message in _packageResult.Messages)
{
if (message.MessageType == ResultType.Error)
{
Expand All @@ -2389,7 +2399,7 @@ public void Should_have_an_error_package_result()
public void Should_have_expected_error_in_package_result()
{
bool errorFound = false;
foreach (var message in packageResult.Messages)
foreach (var message in _packageResult.Messages)
{
if (message.MessageType == ResultType.Error)
{
Expand Down Expand Up @@ -2564,7 +2574,7 @@ public void Should_have_expected_error_in_package_result()
[Platform(Exclude = "Mono")]
public class When_upgrading_a_package_that_errors : ScenariosBase
{
private PackageResult packageResult;
private PackageResult _packageResult;

public override void Context()
{
Expand All @@ -2575,7 +2585,7 @@ public override void Context()
public override void Because()
{
Results = Service.Upgrade(Configuration);
packageResult = Results.FirstOrDefault().Value;
_packageResult = Results.FirstOrDefault().Value;
}

[Fact]
Expand Down Expand Up @@ -2637,26 +2647,26 @@ public void Should_contain_a_warning_message_that_it_was_unable_to_upgrade_a_pac
[Fact]
public void Should_not_have_a_successful_package_result()
{
packageResult.Success.ShouldBeFalse();
_packageResult.Success.ShouldBeFalse();
}

[Fact]
public void Should_not_have_inconclusive_package_result()
{
packageResult.Inconclusive.ShouldBeFalse();
_packageResult.Inconclusive.ShouldBeFalse();
}

[Fact]
public void Should_not_have_warning_package_result()
{
packageResult.Warning.ShouldBeFalse();
_packageResult.Warning.ShouldBeFalse();
}

[Fact]
public void Should_have_an_error_package_result()
{
bool errorFound = false;
foreach (var message in packageResult.Messages)
foreach (var message in _packageResult.Messages)
{
if (message.MessageType == ResultType.Error)
{
Expand All @@ -2671,7 +2681,7 @@ public void Should_have_an_error_package_result()
public void Should_have_expected_error_in_package_result()
{
bool errorFound = false;
foreach (var message in packageResult.Messages)
foreach (var message in _packageResult.Messages)
{
if (message.MessageType == ResultType.Error)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ private void BuildInstallExample(string packageName, StringBuilder sb, string co

private int ReportActionSummary(ConcurrentDictionary<string, PackageResult> packageResults, string actionName)
{
var successes = packageResults.OrEmpty().Where(p => p.Value.Success && !p.Value.Inconclusive);
var successes = packageResults.OrEmpty().Where(p => p.Value.Success && !p.Value.Inconclusive).OrderBy(p => p.Value.Name);
var failures = packageResults.Count(p => !p.Value.Success);
var warnings = packageResults.Count(p => p.Value.Warning);
var rebootPackages = packageResults.Count(p => new[] { 1641, 3010 }.Contains(p.Value.ExitCode));
Expand Down Expand Up @@ -1117,7 +1117,7 @@ private int ReportActionSummary(ConcurrentDictionary<string, PackageResult> pack
{
this.Log().Info("");
this.Log().Warn("Warnings:");
foreach (var warning in packageResults.Where(p => p.Value.Warning).OrEmpty())
foreach (var warning in packageResults.Where(p => p.Value.Warning).OrderBy(p => p.Value.Name).OrEmpty())
{
var warningMessage = warning.Value.Messages.FirstOrDefault(m => m.MessageType == ResultType.Warn);
this.Log().Warn(" - {0}{1}".FormatWith(warning.Value.Name, warningMessage != null ? " - {0}".FormatWith(warningMessage.Message) : string.Empty));
Expand All @@ -1128,7 +1128,7 @@ private int ReportActionSummary(ConcurrentDictionary<string, PackageResult> pack
{
this.Log().Info("");
this.Log().Warn("Packages requiring reboot:");
foreach (var reboot in packageResults.Where(p => new[] { 1641, 3010 }.Contains(p.Value.ExitCode)).OrEmpty())
foreach (var reboot in packageResults.Where(p => new[] { 1641, 3010 }.Contains(p.Value.ExitCode)).OrderBy(p => p.Value.Name).OrEmpty())
{
this.Log().Warn(" - {0}{1}".FormatWith(reboot.Value.Name, reboot.Value.ExitCode != 0 ? " (exit code {0})".FormatWith(reboot.Value.ExitCode) : string.Empty));
}
Expand All @@ -1141,7 +1141,7 @@ The recent package changes indicate a reboot is necessary.
{
this.Log().Info("");
this.Log().Error("Failures");
foreach (var failure in packageResults.Where(p => !p.Value.Success).OrEmpty())
foreach (var failure in packageResults.Where(p => !p.Value.Success).OrderBy(p => p.Value.Name).OrEmpty())
{
var errorMessage = failure.Value.Messages.FirstOrDefault(m => m.MessageType == ResultType.Error);
this.Log().Error(
Expand Down
Loading