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

chore(release): 1.2.1 #24

Merged
merged 11 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
with:
submodules: recursive
fetch-depth: 0
- uses: actions/setup-dotnet@v1
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.x'
- name: Build Deps
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
fetch-depth: 0 # Required by LockCheck CI

- name: Install Dotnet
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: "7.0.x"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
echo Current Version: ${{ steps.get_version.outputs.version }}

- name: Install Dotnet
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: "7.0.x"

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Release 1.2.0
* Prevent hanging on process kill by @domsleee in https://github.com/domsleee/ForceOps/pull/23
* Disable parallelization on tests

## Release 1.2.0
* Add aot, and exe in release
* Add "list" subcommand
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<Description>By hook or by crook, perform operations on files and directories. If they are
in use by a process, kill the process.</Description>
<Version>1.2.0</Version>
<Version>1.2.1</Version>
<PackageProjectUrl>https://github.com/domsleee/forceops</PackageProjectUrl>
<RepositoryUrl>https://github.com/domsleee/forceops</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down
1 change: 1 addition & 0 deletions ForceOps.Test/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[assembly: CollectionBehavior(DisableTestParallelization = true)]
8 changes: 4 additions & 4 deletions ForceOps.Test/src/ListFileOrDirectoryLocksTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public class ListFileOrDirectoryLocksTest : IDisposable
public void WorksForDirectory()
{
var testContext = new TestContext();
using var launchedProcess = LaunchProcessInDirectory(tempDirectoryPath);
using var launchedProcess = LaunchPowershellWithCommand(workingDirectory: tempDirectoryPath);
new ListFileOrDirectoryLocks(testContext.forceOpsContext).PrintLocks(tempDirectoryPath);

var stdoutString = stdoutStringBuilder.ToString();
Assert.Equal($"ProcessId,ExecutableName,ApplicationName\r\n{launchedProcess.process.Id},powershell.exe,powershell.exe\r\n", stdoutString);
var stdoutString = GetStdoutString(stdoutStringBuilder);
Assert.Contains($"ProcessId,ExecutableName,ApplicationName\r\n{launchedProcess.process.Id},powershell.exe,powershell.exe\r\n", stdoutString);
}

[Fact]
Expand All @@ -29,7 +29,7 @@ public void WorksForFile()
using var launchedProcess = HoldLockOnFileUsingPowershell(tempFilePath);
new ListFileOrDirectoryLocks(testContext.forceOpsContext).PrintLocks(tempFilePath);

var stdoutString = stdoutStringBuilder.ToString();
var stdoutString = GetStdoutString(stdoutStringBuilder);
Assert.Equal($"ProcessId,ExecutableName,ApplicationName\r\n{launchedProcess.process.Id},powershell.exe,powershell.exe\r\n", stdoutString);
}

Expand Down
4 changes: 2 additions & 2 deletions ForceOps.Test/src/ProgramTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public void RelaunchedProgramWorks()
string exeNameOverride = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "forceops.exe");
testContext.forceOpsContext.relaunchAsElevated = new RelaunchAsElevated() { verb = "", exeNameOverride = exeNameOverride };
var forceOps = new ForceOps(new[] { "delete", tempDirectoryPath }, testContext.forceOpsContext);
Assert.True(0 == forceOps.Run(), forceOps.caughtException?.ToString() + testContext.fakeLoggerFactory.GetAllLogsString() + stdoutStringBuilder.ToString());
var stdoutString = GetStdoutString(stdoutStringBuilder);
Assert.True(0 == forceOps.Run(), forceOps.caughtException?.ToString() + testContext.fakeLoggerFactory.GetAllLogsString() + stdoutString);
Assert.True(!Directory.Exists(tempDirectoryPath), "Deleted by relaunch");
Assert.Contains("Unable to perform operation as an unelevated process. Retrying as elevated and logging to", testContext.fakeLoggerFactory.GetAllLogsString());
}
Expand Down Expand Up @@ -108,7 +109,6 @@ public void ListNonExistingFileThrowsMessage()
Assert.Equal(@"Cannot list locks of 'C:\C:\C:\'. No such file or directory", testContext.friendlyExitMessage);
}


public ProgramTest()
{
tempDirectoryPath = GetTemporaryFileName();
Expand Down
51 changes: 42 additions & 9 deletions ForceOps.Test/src/TestUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,42 @@ public static WrappedProcess LaunchPowershellWithCommand(string command = "", st
}
};

List<string> output = new();
List<string> error = new();
StartProcessUntilProcessHasBeenLoadedMessage(process);

return new WrappedProcess(process);
}

public static WrappedProcess LaunchCmdWithCommand(string command = "", string workingDirectory = "")
{
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "cmd",
WorkingDirectory = workingDirectory,
Arguments = $"/c \"{command}; echo process has been loaded && timeout /t 10 /nobreak\"",
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
}
};

StartProcessUntilProcessHasBeenLoadedMessage(process);

return new WrappedProcess(process);
}

static void StartProcessUntilProcessHasBeenLoadedMessage(Process process)
{
string output = "";
string error = "";
process.OutputDataReceived += (sender, e) =>
{
if (e.Data != null) output.Add(e.Data);
if (e.Data != null) output += $"{e.Data}{System.Environment.NewLine}";
};
process.ErrorDataReceived += (sender, e) =>
{
if (e.Data != null) error.Add(e.Data);
if (e.Data != null) error += $"{e.Data}{System.Environment.NewLine}";
};

process.Start();
Expand All @@ -48,28 +75,32 @@ public static WrappedProcess LaunchPowershellWithCommand(string command = "", st

var startTime = DateTime.Now;

while (!(output.LastOrDefault() ?? "").EndsWith("process has been loaded") && !process.HasExited)
while (!output.Contains("process has been loaded") && !process.HasExited)
{
Thread.Sleep(50);
if (DateTime.Now.Subtract(startTime).TotalSeconds > 5)
{
throw new Exception("Gave up after waiting 5 seconds");
throw new Exception($"Gave up after waiting 5 seconds.\nOutput: {output}\nError: {error}");
}
}

if (process.HasExited)
{
throw new Exception($"Process has exited unexpectedly.\nOutput: {string.Join("\n", output)}\nError: {string.Join("\n", error)}");
throw new Exception($"Process has exited unexpectedly.\nOutput: {output}\nError: {error}");
}

return new WrappedProcess(process);
}

public static string GetTemporaryFileName()
{
return Path.Join(Path.GetTempPath(), Guid.NewGuid().ToString());
}

public static string GetStdoutString(StringBuilder stdoutStringBuilder)
{
Console.Out.Flush();
return stdoutStringBuilder.ToString();
}

public static IDisposable CreateTemporaryDirectory(string directory)
{
Directory.CreateDirectory(directory);
Expand All @@ -86,11 +117,13 @@ public static IDisposable CreateTemporaryDirectory(string directory)
public static IDisposable RedirectStdout(StringBuilder stringBuilder)
{
var originalConsoleOut = Console.Out;
Console.Out.Flush();
Console.SetOut(new StringWriter(stringBuilder));

return Disposable.Create(() =>
{
Console.SetOut(originalConsoleOut);
Console.Out.Flush();
});
}
}