|
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
4 | 4 | using System.Net.Sockets; |
| 5 | +using System.Runtime.InteropServices; |
5 | 6 | using IntegrationTests.Helpers; |
6 | 7 | using Xunit.Abstractions; |
7 | 8 | using static OpenTelemetry.Proto.Trace.V1.Span.Types; |
@@ -45,7 +46,11 @@ protected virtual void Dispose(bool disposing) |
45 | 46 | } |
46 | 47 | else |
47 | 48 | { |
48 | | - _serverProcess.Process.Kill(); |
| 49 | + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || !SendSigTerm(_serverProcess.Process.Id)) |
| 50 | + { |
| 51 | + _serverProcess.Process.Kill(); |
| 52 | + } |
| 53 | + |
49 | 54 | _serverProcess.Process.WaitForExit(); |
50 | 55 | } |
51 | 56 |
|
@@ -122,4 +127,26 @@ private async Task WaitForServer() |
122 | 127 |
|
123 | 128 | Assert.Fail("WCF Server did not open the port."); |
124 | 129 | } |
| 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 | + } |
125 | 152 | } |
0 commit comments