From: Anton Firszov Date: Fri, 6 Aug 2021 12:36:27 +0000 (+0200) Subject: Define timeout for CreateSocket.Ctor_SafeHandle_Listening_Success (#56717) X-Git-Tag: submit/tizen/20220110.044913~593 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ebc0f05ebc3bb8854dceaf791486b4aa49739e80;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Define timeout for CreateSocket.Ctor_SafeHandle_Listening_Success (#56717) --- diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/CreateSocketTests.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/CreateSocketTests.cs index 334280938e0..552c77e9044 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/CreateSocketTests.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/CreateSocketTests.cs @@ -449,35 +449,38 @@ namespace System.Net.Sockets.Tests [ActiveIssue("https://github.com/dotnet/runtime/issues/52124", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public async Task Ctor_SafeHandle_Listening_Success(bool shareSafeHandle) { - using var listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - listener.Bind(new IPEndPoint(IPAddress.Loopback, 0)); - listener.Listen(); - - using var listenerCopy = new Socket(shareSafeHandle ? listener.SafeHandle : new SafeSocketHandle(listener.Handle, ownsHandle: false)); - Assert.False(listenerCopy.Connected); - // This will throw if _isListening is set internally. (before reaching any real code) - Assert.Throws(() => listenerCopy.Connect(new IPEndPoint(IPAddress.Loopback,0))); - - Assert.Equal(listener.AddressFamily, listenerCopy.AddressFamily); - Assert.Equal(listener.Handle, listenerCopy.Handle); - Assert.Equal(listener.IsBound, listenerCopy.IsBound); - Assert.Equal(listener.LocalEndPoint, listenerCopy.LocalEndPoint); - Assert.Equal(listener.ProtocolType, listenerCopy.ProtocolType); - Assert.Equal(listener.SocketType, listenerCopy.SocketType); - - foreach (Socket listenerSocket in new[] { listener, listenerCopy }) + await Task.Run(async () => { - using (var client1 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + using var listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + listener.Bind(new IPEndPoint(IPAddress.Loopback, 0)); + listener.Listen(); + + using var listenerCopy = new Socket(shareSafeHandle ? listener.SafeHandle : new SafeSocketHandle(listener.Handle, ownsHandle: false)); + Assert.False(listenerCopy.Connected); + // This will throw if _isListening is set internally. (before reaching any real code) + Assert.Throws(() => listenerCopy.Connect(new IPEndPoint(IPAddress.Loopback, 0))); + + Assert.Equal(listener.AddressFamily, listenerCopy.AddressFamily); + Assert.Equal(listener.Handle, listenerCopy.Handle); + Assert.Equal(listener.IsBound, listenerCopy.IsBound); + Assert.Equal(listener.LocalEndPoint, listenerCopy.LocalEndPoint); + Assert.Equal(listener.ProtocolType, listenerCopy.ProtocolType); + Assert.Equal(listener.SocketType, listenerCopy.SocketType); + + foreach (Socket listenerSocket in new[] { listener, listenerCopy }) { - Task connect1 = client1.ConnectAsync(listenerSocket.LocalEndPoint); - using (Socket server1 = listenerSocket.Accept()) + using (var client1 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { - await connect1; - server1.Send(new byte[] { 42 }); - Assert.Equal(1, client1.Receive(new byte[1])); + Task connect1 = client1.ConnectAsync(listenerSocket.LocalEndPoint); + using (Socket server1 = listenerSocket.Accept()) + { + await connect1; + server1.Send(new byte[] { 42 }); + Assert.Equal(1, client1.Receive(new byte[1])); + } } } - } + }).WaitAsync(TestSettings.PassingTestTimeout); } [DllImport("libc")]