From 3154b76da02103dd22bdbbb649fea55eaf9a80f0 Mon Sep 17 00:00:00 2001 From: Tomas Weinfurt Date: Tue, 15 Oct 2019 22:10:51 -0700 Subject: [PATCH] use background thread to wait for address changes on OSX (dotnet/corefx#41768) * use background thread to wait for address changes on OSX * remove RemoteExecutor * update comment Commit migrated from https://github.com/dotnet/corefx/commit/08bf1fec4bbb44bab804f068878812aacb06b4d0 --- .../NetworkInformation/NetworkAddressChange.OSX.cs | 1 + .../NetworkAvailabilityChangedTests.cs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.OSX.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.OSX.cs index baa6ecd5989a0..b5187e13ff25d 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.OSX.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.OSX.cs @@ -181,6 +181,7 @@ private static unsafe void CreateAndStartRunLoop() } } s_runLoopThread = new Thread(RunLoopThreadStart); + s_runLoopThread.IsBackground = true; s_runLoopThread.Start(); s_runLoopStartedEvent.WaitOne(); // Wait for the new thread to finish initialization. } diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAvailabilityChangedTests.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAvailabilityChangedTests.cs index fde4b4f431ed6..138890aa78b34 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAvailabilityChangedTests.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkAvailabilityChangedTests.cs @@ -27,6 +27,20 @@ public void NetworkAvailabilityChanged_JustRemove_Success() NetworkChange.NetworkAvailabilityChanged -= _availabilityHandler; } + [Fact] + [ActiveIssue(33530, TestPlatforms.FreeBSD)] + public void NetworkAddressChanged_Add_DoesNotBlock() + { + // Register without unregistering. + // This should not block process exit. If it does, this test will pass + // but we would fail to exit test run at the end. + // We cannot test this via RemoteInvoke() as that calls Environment.Exit() + // and forces quit even when foreground threads are running. + NetworkChange.NetworkAddressChanged += _addressHandler; + { + }; + } + [Fact] [ActiveIssue(33530, TestPlatforms.FreeBSD)] public void NetworkAddressChanged_AddAndRemove_NetworkAvailabilityChanged_JustRemove_Success()