Repository: dotnet/runtime
File: src/libraries/System.Net.Ping/tests/FunctionalTests/PingTest.cs (C#)

Code before:
                    {
                        tcs.TrySetCanceled();
                    }
                    else if (e.Error != null)
                    {
                        tcs.TrySetException(e.Error);
                    }
                    else
                    {
                        tcs.TrySetResult(e.Reply);
                    }
                }
                sender.PingCompleted += PingCompleted;
                var tcs = new TaskCompletionSource<PingReply>();
                sender.SendAsync(address, tcs);
                PingReply reply = await tcs.Task;
                sender.PingCompleted -= PingCompleted;
                return reply;
            });

        [Fact]
        [OuterLoop]
        public Task Ping_TimedOut_TAP_Success()
            => Ping_TimedOut_Core((sender, address) => sender.SendPingAsync(address));

        private static bool IsRemoteExecutorSupportedAndPrivilegedProcess => RemoteExecutor.IsSupported && PlatformDetection.IsPrivilegedProcess;

        [PlatformSpecific(TestPlatforms.AnyUnix)]
        [ConditionalTheory(nameof(IsRemoteExecutorSupportedAndPrivilegedProcess))]
        [InlineData(AddressFamily.InterNetwork)]
        [InlineData(AddressFamily.InterNetworkV6)]
        [OuterLoop("Requires sudo access")]
        public void SendPingWithIPAddressAndTimeoutAndBufferAndPingOptions_ElevatedUnix(AddressFamily addressFamily)
        {
            IPAddress localIpAddress = TestSettings.GetLocalIPAddress(addressFamily);
            if (localIpAddress == null)
            {
                // No local address for given address family.
                return;
            }

            _output.WriteLine($"pinging '{localIpAddress}'");

            RemoteExecutor.Invoke(address =>
            {
                byte[] buffer = TestSettings.PayloadAsBytes;
                SendBatchPing(
                    (ping) => ping.Send(address, TestSettings.PingTimeout, buffer, new PingOptions()),
                    (pingReply) =>
                    {
                        PingResultValidator(pingReply, new IPAddress[] { IPAddress.Parse(address) }, null);

Review comment (suggestion):
The ConditionalFact attribute should include a condition for threading support since this test uses SendPingAsync which requires threading. The pattern used throughout this file for async tests is ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported)). This ensures the test is skipped on platforms without threading support.
```suggestion
        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
```

Code after:
                static void PingCompleted(object sender, PingCompletedEventArgs e)
                {
                    var tcs = (TaskCompletionSource<PingReply>)e.UserState;

                    if (e.Cancelled)
                    {
                        tcs.TrySetCanceled();
                    }
                    else if (e.Error != null)
                    {
                        tcs.TrySetException(e.Error);
                    }
                    else
                    {
                        tcs.TrySetResult(e.Reply);
                    }
                }
                sender.PingCompleted += PingCompleted;
                var tcs = new TaskCompletionSource<PingReply>();
                sender.SendAsync(address, tcs);
                PingReply reply = await tcs.Task;
                sender.PingCompleted -= PingCompleted;
                return reply;
            });

        [ConditionalFact]
        [OuterLoop]
        public Task Ping_TimedOut_TAP_Success()
            => Ping_TimedOut_Core((sender, address) => sender.SendPingAsync(address));

        private static bool IsRemoteExecutorSupportedAndPrivilegedProcess => RemoteExecutor.IsSupported && PlatformDetection.IsPrivilegedProcess;

        [PlatformSpecific(TestPlatforms.AnyUnix)]
        [ConditionalTheory(nameof(IsRemoteExecutorSupportedAndPrivilegedProcess))]
        [InlineData(AddressFamily.InterNetwork)]
        [InlineData(AddressFamily.InterNetworkV6)]
        [OuterLoop("Requires sudo access")]
        public void SendPingWithIPAddressAndTimeoutAndBufferAndPingOptions_ElevatedUnix(AddressFamily addressFamily)
        {
            IPAddress localIpAddress = TestSettings.GetLocalIPAddress(addressFamily);
            if (localIpAddress == null)
            {
                // No local address for given address family.
                return;
            }

            _output.WriteLine($"pinging '{localIpAddress}'");

            RemoteExecutor.Invoke(address =>
            {
                byte[] buffer = TestSettings.PayloadAsBytes;