From 3ba8c2d3f0d2d4859586d4d14a1b064ef70c750c Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 29 Jun 2017 11:50:21 -0700 Subject: [PATCH] Add ListenHandleTests (#1923) --- .../ListenHandleTests.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ListenHandleTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ListenHandleTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ListenHandleTests.cs new file mode 100644 index 0000000000..71278e954c --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ListenHandleTests.cs @@ -0,0 +1,40 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Net; +using System.Net.Sockets; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Testing; +using Microsoft.AspNetCore.Testing.xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + [OSSkipCondition(OperatingSystems.Windows, SkipReason = "Listening to open TCP socket and/or pipe handles is not supported on Windows.")] + public class ListenHandleTests + { + [ConditionalFact] + public async Task CanListenToOpenTcpSocketHandle() + { + using (var listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + listenSocket.Bind(new IPEndPoint(IPAddress.Loopback, 0)); + + using (var server = new TestServer(_ => Task.CompletedTask, new TestServiceContext(), new ListenOptions((ulong)listenSocket.Handle))) + { + using (var connection = new TestConnection(((IPEndPoint)listenSocket.LocalEndPoint).Port)) + { + await connection.SendEmptyGet(); + + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } + } + } +}