Skip to content

Commit 3ba8c2d

Browse files
authored
Add ListenHandleTests (#1923)
1 parent a247a3d commit 3ba8c2d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Net;
5+
using System.Net.Sockets;
6+
using System.Threading.Tasks;
7+
using Microsoft.AspNetCore.Server.Kestrel.Core;
8+
using Microsoft.AspNetCore.Testing;
9+
using Microsoft.AspNetCore.Testing.xunit;
10+
11+
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
12+
{
13+
[OSSkipCondition(OperatingSystems.Windows, SkipReason = "Listening to open TCP socket and/or pipe handles is not supported on Windows.")]
14+
public class ListenHandleTests
15+
{
16+
[ConditionalFact]
17+
public async Task CanListenToOpenTcpSocketHandle()
18+
{
19+
using (var listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
20+
{
21+
listenSocket.Bind(new IPEndPoint(IPAddress.Loopback, 0));
22+
23+
using (var server = new TestServer(_ => Task.CompletedTask, new TestServiceContext(), new ListenOptions((ulong)listenSocket.Handle)))
24+
{
25+
using (var connection = new TestConnection(((IPEndPoint)listenSocket.LocalEndPoint).Port))
26+
{
27+
await connection.SendEmptyGet();
28+
29+
await connection.Receive(
30+
"HTTP/1.1 200 OK",
31+
$"Date: {server.Context.DateHeaderValue}",
32+
"Content-Length: 0",
33+
"",
34+
"");
35+
}
36+
}
37+
}
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)