Skip to content

Commit d2115a7

Browse files
committed
Make test .NET 6 compatible.
1 parent f3b6fb8 commit d2115a7

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Turkey.Tests/ProcessExtensionsTest.cs

+10-7
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ public async Task WaitForExitAsync_DoesNotHangForOrphanedGrandChildren()
2020
{
2121
// This script creates a 'sleep' grandchild that outlives its parent.
2222
File.WriteAllText(filename,
23-
$"""
24-
#!/bin/bash
23+
$@"#!/bin/bash
2524
26-
sleep {GrandChildAgeSeconds} &
27-
""");
28-
File.SetUnixFileMode(filename, UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute);
25+
sleep {GrandChildAgeSeconds} &
26+
");
27+
Process chmodProcess = Process.Start("chmod", $"+x {filename}");
28+
chmodProcess.WaitForExit();
29+
Assert.Equal(0, chmodProcess.ExitCode);
2930

3031
var psi = new ProcessStartInfo()
3132
{
@@ -36,14 +37,16 @@ public async Task WaitForExitAsync_DoesNotHangForOrphanedGrandChildren()
3637
using Process process = Process.Start(psi);
3738

3839
// Use a shorter timeout for WaitForExitAsync than the grandchild lives.
39-
long startTime = Stopwatch.GetTimestamp();
40+
Stopwatch stopWatch = new Stopwatch();
41+
stopWatch.Start();
4042
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(WaitTimeoutSeconds));
4143

4244
// The WaitForExit completes by cancellation.
4345
await Assert.ThrowsAsync<TaskCanceledException>(() => process.WaitForExitAsync(cts.Token, new StringWriter(), new StringWriter()));
4446

4547
// The completion takes at least the WaitTime.
46-
TimeSpan elapsedTime = Stopwatch.GetElapsedTime(startTime);
48+
stopWatch.Stop();
49+
TimeSpan elapsedTime = stopWatch.Elapsed;
4750
Assert.True(elapsedTime >= TimeSpan.FromSeconds(WaitTimeoutSeconds), "The grandchild is not keeping the script alive");
4851
}
4952
finally

Turkey.Tests/Turkey.Tests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
<IsPackable>false</IsPackable>
66
<RollForward>Major</RollForward>
77
</PropertyGroup>

0 commit comments

Comments
 (0)