-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[wasm][testing] hosting webSocket echo server in xharness process #52546
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/libraries/Common/tests/System/Net/Prerequisites/MonoNetTestServer/GenericHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Http.Features; | ||
|
||
namespace MonoNetTestServer | ||
{ | ||
public class GenericHandler | ||
{ | ||
RequestDelegate next; | ||
public GenericHandler(RequestDelegate next) | ||
{ | ||
this.next = next; | ||
} | ||
|
||
public async Task Invoke(HttpContext context) | ||
{ | ||
PathString path = context.Request.Path; | ||
if (path.Equals(new PathString("/remoteLoop"))) | ||
{ | ||
await RemoteLoopHandler.InvokeAsync(context); | ||
return; | ||
} | ||
|
||
await next(context); | ||
} | ||
} | ||
|
||
public static class GenericHandlerExtensions | ||
{ | ||
public static IApplicationBuilder UseGenericHandler(this IApplicationBuilder builder) | ||
{ | ||
return builder.UseMiddleware<GenericHandler>(); | ||
} | ||
|
||
public static void SetStatusDescription(this HttpResponse response, string description) | ||
{ | ||
response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = description; | ||
} | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
...ies/Common/tests/System/Net/Prerequisites/MonoNetTestServer/Handlers/RemoteLoopHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Net; | ||
using System.Net.Sockets; | ||
using System.Net.WebSockets; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace MonoNetTestServer | ||
{ | ||
public class RemoteLoopHandler | ||
{ | ||
private const int MaxBufferSize = 128 * 1024; | ||
|
||
public static async Task InvokeAsync(HttpContext context) | ||
{ | ||
try | ||
{ | ||
if (!context.WebSockets.IsWebSocketRequest) | ||
{ | ||
context.Response.StatusCode = 400; | ||
context.Response.ContentType = "text/plain"; | ||
await context.Response.WriteAsync("Not a websocket request"); | ||
|
||
return; | ||
} | ||
|
||
using (WebSocket socket = await context.WebSockets.AcceptWebSocketAsync()) | ||
{ | ||
await ProcessWebSocketRequest(context, socket); | ||
} | ||
|
||
} | ||
catch (Exception) | ||
{ | ||
// We might want to log these exceptions. But for now we ignore them. | ||
} | ||
} | ||
|
||
enum CommandType | ||
{ | ||
Listen, | ||
Open, | ||
Send, | ||
Receive, | ||
Close | ||
} | ||
|
||
class Command | ||
{ | ||
public CommandType Type { get; set; } | ||
public byte[] Data { get; set; } | ||
public int Port { get; set; } | ||
public int ListenBacklog { get; set; } | ||
public IPAddress Address { get; set; } | ||
} | ||
|
||
private static async Task ProcessWebSocketRequest(HttpContext context, WebSocket webSocket) | ||
{ | ||
Socket listenSocket = null; | ||
Socket current = null; | ||
Memory<byte> ms = new Memory<byte>(); | ||
|
||
ValueWebSocketReceiveResult result = await webSocket.ReceiveAsync(ms, CancellationToken.None); | ||
while (result.MessageType != WebSocketMessageType.Close) | ||
{ | ||
Command command = null; // get bytes=> json=>command | ||
switch (command.Type) | ||
{ | ||
case CommandType.Listen: | ||
listenSocket = new Socket(command.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp); | ||
listenSocket.Bind(new IPEndPoint(command.Address, 0)); | ||
listenSocket.Listen(command.ListenBacklog); | ||
break; | ||
case CommandType.Open: | ||
current = await listenSocket.AcceptAsync().ConfigureAwait(false); | ||
break; | ||
case CommandType.Close: | ||
current.Close(); | ||
break; | ||
} | ||
|
||
result = await webSocket.ReceiveAsync(ms, CancellationToken.None); | ||
} | ||
await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "closing remoteLoop", CancellationToken.None); | ||
|
||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...ibraries/Common/tests/System/Net/Prerequisites/MonoNetTestServer/MonoNetTestServer.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel> | ||
<OutputType>Exe</OutputType> | ||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="Handlers\RemoteLoopHandler.cs" /> | ||
<Compile Include="GenericHandler.cs" /> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Startup.cs" /> | ||
</ItemGroup> | ||
</Project> |
23 changes: 23 additions & 0 deletions
23
src/libraries/Common/tests/System/Net/Prerequisites/MonoNetTestServer/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace MonoNetTestServer | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
CreateHostBuilder(args).Build().Run(); | ||
} | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
}); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/libraries/Common/tests/System/Net/Prerequisites/MonoNetTestServer/Startup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace MonoNetTestServer | ||
{ | ||
public class Startup | ||
{ | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | ||
{ | ||
app.UseWebSockets(); | ||
app.UseGenericHandler(); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...ries/Common/tests/System/Net/Prerequisites/MonoNetTestServer/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Debug", | ||
"System": "Information", | ||
"Microsoft": "Information" | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/libraries/Common/tests/System/Net/Prerequisites/MonoNetTestServer/appsettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
25 changes: 0 additions & 25 deletions
25
src/libraries/Common/tests/System/Net/Prerequisites/NetCoreServer.sln
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/libraries/Common/tests/System/Net/Prerequisites/NetCoreServer/NetCoreServer.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/libraries/Common/tests/System/Net/Prerequisites/NetTestServers.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.31229.75 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MonoNetTestServer", "MonoNetTestServer\MonoNetTestServer.csproj", "{86E9A13D-9F4A-45DE-B0BB-CBB6A6533868}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCoreServer", "NetCoreServer\NetCoreServer.csproj", "{2BB687CC-3F0C-43A9-8F38-140E91892EB0}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{86E9A13D-9F4A-45DE-B0BB-CBB6A6533868}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{86E9A13D-9F4A-45DE-B0BB-CBB6A6533868}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{86E9A13D-9F4A-45DE-B0BB-CBB6A6533868}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{86E9A13D-9F4A-45DE-B0BB-CBB6A6533868}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{2BB687CC-3F0C-43A9-8F38-140E91892EB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{2BB687CC-3F0C-43A9-8F38-140E91892EB0}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{2BB687CC-3F0C-43A9-8F38-140E91892EB0}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{2BB687CC-3F0C-43A9-8F38-140E91892EB0}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {2F9A0637-452E-4FB9-9403-CB52944982DA} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,36 +3,26 @@ | |
<StringResourcesPath>../src/Resources/Strings.resx</StringResourcesPath> | ||
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppCurrent)-Browser</TargetFrameworks> | ||
<DefineConstants>$(DefineConstants);NETSTANDARD</DefineConstants> | ||
<Scenario>WasmTestOnBrowser</Scenario> | ||
<WasmXHarnessArgs>$(WasmXHarnessArgs) --set-web-server-env --web-server-middleware=$(ArtifactsDir)bin/MonoNetTestServer/net5.0-$(Configuration)/MonoNetTestServer.dll --web-server-middleware=$(ArtifactsDir)bin/NetCoreServer/net5.0-$(Configuration)/NetCoreServer.dll</WasmXHarnessArgs> | ||
</PropertyGroup> | ||
<!-- Do not reference these assemblies from the TargetingPack since we are building part of the source code for tests. --> | ||
<ItemGroup> | ||
<DefaultReferenceExclusion Include="System.Configuration" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="$(CommonTestPath)System\Net\Capability.Security.cs" | ||
Link="Common\System\Net\Capability.Security.cs" /> | ||
<Compile Include="$(CommonTestPath)System\Net\Configuration.cs" | ||
Link="Common\System\Net\Configuration.cs" /> | ||
<Compile Include="$(CommonTestPath)System\Net\Configuration.Certificates.cs" | ||
Link="Common\System\Net\Configuration.Certificates.cs" /> | ||
<Compile Include="$(CommonTestPath)System\Net\Configuration.Http.cs" | ||
Link="Common\System\Net\Configuration.Http.cs" /> | ||
<Compile Include="$(CommonTestPath)System\Net\Configuration.Security.cs" | ||
Link="Common\System\Net\Configuration.Security.cs" /> | ||
<Compile Include="$(CommonTestPath)System\Net\Configuration.WebSockets.cs" | ||
Link="Common\System\Net\Configuration.WebSockets.cs" /> | ||
<Compile Include="$(CommonTestPath)System\Net\EventSourceTestLogging.cs" | ||
Link="Common\System\Net\EventSourceTestLogging.cs" /> | ||
<Compile Include="$(CommonTestPath)System\Net\Http\LoopbackProxyServer.cs" | ||
Link="Common\System\Net\Http\LoopbackProxyServer.cs" /> | ||
<Compile Include="$(CommonTestPath)System\Net\Http\LoopbackServer.cs" | ||
Link="Common\System\Net\Http\LoopbackServer.cs" /> | ||
<Compile Include="$(CommonTestPath)System\Net\Http\GenericLoopbackServer.cs" | ||
Link="Common\System\Net\Http\GenericLoopbackServer.cs" /> | ||
<Compile Include="$(CommonTestPath)System\Security\Cryptography\PlatformSupport.cs" | ||
Link="CommonTest\System\Security\Cryptography\PlatformSupport.cs" /> | ||
<Compile Include="$(CommonTestPath)System\Threading\Tasks\TaskTimeoutExtensions.cs" | ||
Link="Common\System\Threading\Tasks\TaskTimeoutExtensions.cs" /> | ||
<Compile Include="$(CommonTestPath)System\Net\Capability.Security.cs" Link="Common\System\Net\Capability.Security.cs" /> | ||
<Compile Include="$(CommonTestPath)System\Net\Configuration.cs" Link="Common\System\Net\Configuration.cs" /> | ||
<Compile Include="$(CommonTestPath)System\Net\Configuration.Certificates.cs" Link="Common\System\Net\Configuration.Certificates.cs" /> | ||
<Compile Include="$(CommonTestPath)System\Net\Configuration.Http.cs" Link="Common\System\Net\Configuration.Http.cs" /> | ||
<Compile Include="$(CommonTestPath)System\Net\Configuration.Security.cs" Link="Common\System\Net\Configuration.Security.cs" /> | ||
<Compile Include="$(CommonTestPath)System\Net\Configuration.WebSockets.cs" Link="Common\System\Net\Configuration.WebSockets.cs" /> | ||
<Compile Include="$(CommonTestPath)System\Net\EventSourceTestLogging.cs" Link="Common\System\Net\EventSourceTestLogging.cs" /> | ||
<Compile Include="$(CommonTestPath)System\Net\Http\LoopbackProxyServer.cs" Link="Common\System\Net\Http\LoopbackProxyServer.cs" /> | ||
<Compile Include="$(CommonTestPath)System\Net\Http\LoopbackServer.cs" Link="Common\System\Net\Http\LoopbackServer.cs" /> | ||
<Compile Include="$(CommonTestPath)System\Net\Http\GenericLoopbackServer.cs" Link="Common\System\Net\Http\GenericLoopbackServer.cs" /> | ||
<Compile Include="$(CommonTestPath)System\Security\Cryptography\PlatformSupport.cs" Link="CommonTest\System\Security\Cryptography\PlatformSupport.cs" /> | ||
<Compile Include="$(CommonTestPath)System\Threading\Tasks\TaskTimeoutExtensions.cs" Link="Common\System\Threading\Tasks\TaskTimeoutExtensions.cs" /> | ||
<Compile Include="AbortTest.cs" /> | ||
<Compile Include="CancelTest.cs" /> | ||
<Compile Include="ClientWebSocketOptionsTests.cs" /> | ||
|
@@ -51,4 +41,10 @@ | |
<ItemGroup> | ||
<PackageReference Include="System.Net.TestData" Version="$(SystemNetTestDataVersion)" /> | ||
</ItemGroup> | ||
<ItemGroup Condition="'$(TargetOS)' == 'Browser'"> | ||
<!-- TODO | ||
<ProjectReference Include="$(CommonTestPath)System/Net/Prerequisites/MonoNetTestServer/MonoNetTestServer.csproj" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
<ProjectReference Include="$(CommonTestPath)System/Net/Prerequisites/NetCoreServer/NetCoreServer.csproj" /> | ||
--> | ||
</ItemGroup> | ||
</Project> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be
$(NetCoreAppToolCurrent)