Skip to content

Commit d03add8

Browse files
committed
[CoreWCF.Tests] Gracefully shutdown server
1 parent caec3cd commit d03add8

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

test/IntegrationTests/WcfTestsBase.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
using System.Net.Sockets;
5+
using System.Runtime.InteropServices;
56
using IntegrationTests.Helpers;
67
using Xunit.Abstractions;
78
using static OpenTelemetry.Proto.Trace.V1.Span.Types;
@@ -45,7 +46,11 @@ protected virtual void Dispose(bool disposing)
4546
}
4647
else
4748
{
48-
_serverProcess.Process.Kill();
49+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || !SendSigTerm(_serverProcess.Process.Id))
50+
{
51+
_serverProcess.Process.Kill();
52+
}
53+
4954
_serverProcess.Process.WaitForExit();
5055
}
5156

@@ -122,4 +127,26 @@ private async Task WaitForServer()
122127

123128
Assert.Fail("WCF Server did not open the port.");
124129
}
130+
131+
[DllImport("libc", SetLastError = true)]
132+
#pragma warning disable CA5392 // Use DefaultDllImportSearchPaths attribute for P/Invokes
133+
#pragma warning disable SA1204 // Static elements should appear before instance elements
134+
#pragma warning disable SA1300 // Element should begin with upper-case letter
135+
private static extern int kill(int pid, int sig);
136+
#pragma warning restore SA1300 // Element should begin with upper-case letter
137+
#pragma warning restore SA1204 // Static elements should appear before instance elements
138+
#pragma warning restore CA5392 // Use DefaultDllImportSearchPaths attribute for P/Invokes
139+
140+
private static bool SendSigTerm(int processId)
141+
{
142+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
143+
{
144+
const int sigTerm = 15;
145+
var result = kill(processId, sigTerm);
146+
147+
return result == 0;
148+
}
149+
150+
return false;
151+
}
125152
}

test/test-applications/integrations/TestApplication.Wcf.Core/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
// Configure NetTcp transport
2727
builder.WebHost.UseNetTcp(9090);
2828

29-
var app = builder.Build();
29+
using var app = builder.Build();
3030

3131
// Configure CoreWCF
3232
app.UseServiceModel(serviceBuilder =>

0 commit comments

Comments
 (0)