Skip to content

Commit fb61be4

Browse files
authored
[wasm][testing] hosting echo server in xharness process (#52923)
- move tests to inner loop - include echo middleware in xharness server - improve doc - more granular ActiveIssue #53592 for lack of TRACE - more granular ActiveIssue #53591 for content on GET/HEAD - more granular ActiveIssue #53874 for HttpRequestMessage.Headers.Host - more granular ActiveIssue #53872 for NPE on System.Net.Http.BrowserHttpHandler - more granular ActiveIssue #53876 - include middleware in Helix correlation payload
1 parent 78579ef commit fb61be4

20 files changed

+202
-122
lines changed

docs/workflow/testing/libraries/testing-wasm.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ The following shows how to run tests for a specific library
100100
101101
- `$(WasmXHarnessArgs)` - xharness command arguments
102102
103-
Example: `WasmXHarnessArgs="--xyz"` -> becomes `dotnet xharness wasm test --xyz`
103+
Example: `WasmXHarnessArgs="--set-web-server-http-env=DOTNET_TEST_WEBSOCKETHOST"` -> becomes `dotnet xharness wasm test --set-web-server-http-env=DOTNET_TEST_WEBSOCKETHOST`
104104
105-
- `$(WasmXHarnessMonoArgs)` - arguments to mono
105+
- `$(WasmXHarnessMonoArgs)` - arguments and variables for mono
106106
107-
Example: `WasmXHarnessMonoArgs="--runtime-arg=--trace=E"`
107+
Example: `WasmXHarnessMonoArgs="--runtime-arg=--trace=E --setenv=MONO_LOG_LEVEL=debug"`
108108
109109
- `$(WasmTestAppArgs)` - arguments for the test app itself
110110

src/libraries/Common/tests/System/Net/Configuration.Http.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ public static partial class Http
1212
{
1313
private static readonly string DefaultHttp2AzureServer = "corefx-net-http2.azurewebsites.net";
1414

15+
// for the local server hosted in XHarness we are passing also port as part of the environment variables, because it's bound to random port number
1516
public static string Host => GetValue("DOTNET_TEST_HTTPHOST", DefaultAzureServer);
16-
1717
public static string SecureHost => GetValue("DOTNET_TEST_SECUREHTTPHOST", DefaultAzureServer);
18-
1918
public static string Http2Host => GetValue("DOTNET_TEST_HTTP2HOST", DefaultHttp2AzureServer);
19+
public static int Port = GetPortValue("DOTNET_TEST_HTTPHOST", 80);
20+
public static int SecurePort = GetPortValue("DOTNET_TEST_SECUREHTTPHOST", 443);
2021

2122
// This server doesn't use HTTP/2 server push (push promise) feature. Some HttpClient implementations
2223
// don't support servers that use push right now.

src/libraries/Common/tests/System/Net/Configuration.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,25 @@ private static string GetValue(string envName, string defaultValue=null)
2121
return Environment.ExpandEnvironmentVariables(envValue);
2222
}
2323

24+
private static int GetPortValue(string envName, int defaultValue)
25+
{
26+
string envValue = Environment.GetEnvironmentVariable(envName);
27+
28+
if (string.IsNullOrWhiteSpace(envValue))
29+
{
30+
return defaultValue;
31+
}
32+
envValue = Environment.ExpandEnvironmentVariables(envValue);
33+
34+
var split = envValue.Split(':');
35+
if (split.Length<2)
36+
{
37+
return defaultValue;
38+
}
39+
40+
return int.Parse(split[1]);
41+
}
42+
2443
private static Uri GetUriValue(string envName, Uri defaultValue=null)
2544
{
2645
string envValue = GetValue(envName, null);

src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.RemoteServer.cs

Lines changed: 50 additions & 44 deletions
Large diffs are not rendered by default.

src/libraries/Common/tests/System/Net/Http/PostScenarioTest.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public abstract class PostScenarioTest : HttpClientHandlerTestBase
2828
public PostScenarioTest(ITestOutputHelper output) : base(output) { }
2929

3030
#if !NETFRAMEWORK
31-
[OuterLoop("Uses external servers")]
31+
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
3232
[Theory, MemberData(nameof(RemoteServersMemberData))]
33-
[ActiveIssue("https://github.com/dotnet/runtime/issues/53018", TestPlatforms.Browser)]
33+
[ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)]
3434
public async Task PostRewindableStreamContentMultipleTimes_StreamContentFullySent(Configuration.Http.RemoteServer remoteServer)
3535
{
3636
const string requestBody = "ABC";
@@ -53,17 +53,17 @@ public async Task PostRewindableStreamContentMultipleTimes_StreamContentFullySen
5353
}
5454
#endif
5555

56-
[OuterLoop("Uses external servers")]
56+
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
5757
[MemberData(nameof(RemoteServersMemberData))]
5858
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBrowserDomSupportedOrNotBrowser))]
59-
[ActiveIssue("https://github.com/dotnet/runtime/issues/53018", TestPlatforms.Browser)]
59+
[ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)]
6060
public async Task PostNoContentUsingContentLengthSemantics_Success(Configuration.Http.RemoteServer remoteServer)
6161
{
6262
await PostHelper(remoteServer, string.Empty, null,
6363
useContentLengthUpload: true, useChunkedEncodingUpload: false);
6464
}
6565

66-
[OuterLoop("Uses external servers")]
66+
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
6767
[Theory, MemberData(nameof(RemoteServersMemberData))]
6868
[ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)]
6969
public async Task PostEmptyContentUsingContentLengthSemantics_Success(Configuration.Http.RemoteServer remoteServer)
@@ -72,7 +72,7 @@ public async Task PostEmptyContentUsingContentLengthSemantics_Success(Configurat
7272
useContentLengthUpload: true, useChunkedEncodingUpload: false);
7373
}
7474

75-
[OuterLoop("Uses external servers")]
75+
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
7676
[Theory, MemberData(nameof(RemoteServersMemberData))]
7777
[ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)]
7878
public async Task PostEmptyContentUsingChunkedEncoding_Success(Configuration.Http.RemoteServer remoteServer)
@@ -81,7 +81,7 @@ public async Task PostEmptyContentUsingChunkedEncoding_Success(Configuration.Htt
8181
useContentLengthUpload: false, useChunkedEncodingUpload: true);
8282
}
8383

84-
[OuterLoop("Uses external servers")]
84+
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
8585
[Theory, MemberData(nameof(RemoteServersMemberData))]
8686
[ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)]
8787
public async Task PostEmptyContentUsingConflictingSemantics_Success(Configuration.Http.RemoteServer remoteServer)
@@ -90,7 +90,7 @@ public async Task PostEmptyContentUsingConflictingSemantics_Success(Configuratio
9090
useContentLengthUpload: true, useChunkedEncodingUpload: true);
9191
}
9292

93-
[OuterLoop("Uses external servers")]
93+
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
9494
[Theory, MemberData(nameof(RemoteServersMemberData))]
9595
[ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)]
9696
public async Task PostUsingContentLengthSemantics_Success(Configuration.Http.RemoteServer remoteServer)
@@ -99,7 +99,7 @@ public async Task PostUsingContentLengthSemantics_Success(Configuration.Http.Rem
9999
useContentLengthUpload: true, useChunkedEncodingUpload: false);
100100
}
101101

102-
[OuterLoop("Uses external servers")]
102+
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
103103
[Theory, MemberData(nameof(RemoteServersMemberData))]
104104
[ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)]
105105
public async Task PostUsingChunkedEncoding_Success(Configuration.Http.RemoteServer remoteServer)
@@ -108,7 +108,7 @@ public async Task PostUsingChunkedEncoding_Success(Configuration.Http.RemoteServ
108108
useContentLengthUpload: false, useChunkedEncodingUpload: true);
109109
}
110110

111-
[OuterLoop("Uses external servers")]
111+
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
112112
[Theory, MemberData(nameof(RemoteServersMemberData))]
113113
[ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)]
114114
public async Task PostSyncBlockingContentUsingChunkedEncoding_Success(Configuration.Http.RemoteServer remoteServer)
@@ -117,7 +117,7 @@ public async Task PostSyncBlockingContentUsingChunkedEncoding_Success(Configurat
117117
useContentLengthUpload: false, useChunkedEncodingUpload: true);
118118
}
119119

120-
[OuterLoop("Uses external servers")]
120+
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
121121
[Theory, MemberData(nameof(RemoteServersMemberData))]
122122
[ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)]
123123
public async Task PostRepeatedFlushContentUsingChunkedEncoding_Success(Configuration.Http.RemoteServer remoteServer)
@@ -126,7 +126,7 @@ public async Task PostRepeatedFlushContentUsingChunkedEncoding_Success(Configura
126126
useContentLengthUpload: false, useChunkedEncodingUpload: true);
127127
}
128128

129-
[OuterLoop("Uses external servers")]
129+
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
130130
[Theory, MemberData(nameof(RemoteServersMemberData))]
131131
[ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)]
132132
public async Task PostUsingUsingConflictingSemantics_UsesChunkedSemantics(Configuration.Http.RemoteServer remoteServer)
@@ -135,7 +135,7 @@ public async Task PostUsingUsingConflictingSemantics_UsesChunkedSemantics(Config
135135
useContentLengthUpload: true, useChunkedEncodingUpload: true);
136136
}
137137

138-
[OuterLoop("Uses external servers")]
138+
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
139139
[Theory, MemberData(nameof(RemoteServersMemberData))]
140140
[ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)]
141141
public async Task PostUsingNoSpecifiedSemantics_UsesChunkedSemantics(Configuration.Http.RemoteServer remoteServer)
@@ -154,7 +154,7 @@ public static IEnumerable<object[]> RemoteServersAndLargeContentSizes()
154154
}
155155
}
156156

157-
[OuterLoop("Uses external servers")]
157+
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
158158
[Theory]
159159
[MemberData(nameof(RemoteServersAndLargeContentSizes))]
160160
[ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)]
@@ -223,10 +223,10 @@ public async Task PostNonRewindableContentUsingAuth_PreAuthenticate_Success(Conf
223223
await PostUsingAuthHelper(remoteServer, ExpectedContent, content, credential, preAuthenticate: true);
224224
}
225225

226-
[OuterLoop("Uses external servers")]
226+
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
227227
[MemberData(nameof(RemoteServersMemberData))]
228228
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBrowserDomSupportedOrNotBrowser))]
229-
[ActiveIssue("https://github.com/dotnet/runtime/issues/53018", TestPlatforms.Browser)]
229+
[ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)]
230230
public async Task PostAsync_EmptyContent_ContentTypeHeaderNotSent(Configuration.Http.RemoteServer remoteServer)
231231
{
232232
using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer))

src/libraries/Common/tests/System/Net/Http/ResponseStreamTest.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public static IEnumerable<object[]> RemoteServersAndReadModes()
3030
}
3131

3232
}
33-
[OuterLoop("Uses external servers")]
33+
34+
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
3435
[Theory, MemberData(nameof(RemoteServersAndReadModes))]
35-
[ActiveIssue("https://github.com/dotnet/runtime/issues/53018", TestPlatforms.Browser)]
3636
public async Task GetStreamAsync_ReadToEnd_Success(Configuration.Http.RemoteServer remoteServer, int readMode)
3737
{
3838
using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer))
@@ -126,9 +126,9 @@ public async Task GetStreamAsync_ReadToEnd_Success(Configuration.Http.RemoteServ
126126
}
127127
}
128128

129-
[OuterLoop("Uses external servers")]
129+
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
130130
[Theory, MemberData(nameof(RemoteServersMemberData))]
131-
[ActiveIssue("https://github.com/dotnet/runtime/issues/53018", TestPlatforms.Browser)]
131+
[ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)]
132132
public async Task GetAsync_UseResponseHeadersReadAndCallLoadIntoBuffer_Success(Configuration.Http.RemoteServer remoteServer)
133133
{
134134
using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer))
@@ -146,9 +146,9 @@ public async Task GetAsync_UseResponseHeadersReadAndCallLoadIntoBuffer_Success(C
146146
}
147147
}
148148

149-
[OuterLoop("Uses external servers")]
149+
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
150150
[Theory, MemberData(nameof(RemoteServersMemberData))]
151-
[ActiveIssue("https://github.com/dotnet/runtime/issues/53018", TestPlatforms.Browser)]
151+
[ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)]
152152
public async Task GetAsync_UseResponseHeadersReadAndCopyToMemoryStream_Success(Configuration.Http.RemoteServer remoteServer)
153153
{
154154
using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer))
@@ -171,9 +171,8 @@ public async Task GetAsync_UseResponseHeadersReadAndCopyToMemoryStream_Success(C
171171
}
172172
}
173173

174-
[OuterLoop("Uses external servers")]
174+
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
175175
[Theory, MemberData(nameof(RemoteServersMemberData))]
176-
[ActiveIssue("https://github.com/dotnet/runtime/issues/53018", TestPlatforms.Browser)]
177176
public async Task GetStreamAsync_ReadZeroBytes_Success(Configuration.Http.RemoteServer remoteServer)
178177
{
179178
using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer))
@@ -187,9 +186,8 @@ public async Task GetStreamAsync_ReadZeroBytes_Success(Configuration.Http.Remote
187186
}
188187
}
189188

190-
[OuterLoop("Uses external servers")]
189+
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
191190
[Theory, MemberData(nameof(RemoteServersMemberData))]
192-
[ActiveIssue("https://github.com/dotnet/runtime/issues/53018", TestPlatforms.Browser)]
193191
public async Task ReadAsStreamAsync_Cancel_TaskIsCanceled(Configuration.Http.RemoteServer remoteServer)
194192
{
195193
var cts = new CancellationTokenSource();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project>
2+
<PropertyGroup Condition="'$(TargetOS)' == 'Browser'">
3+
<Scenario>WasmTestOnBrowser</Scenario>
4+
<TestArchiveTestsRoot>$(TestArchiveRoot)browseronly/</TestArchiveTestsRoot>
5+
<TestArchiveTestsDir>$(TestArchiveTestsRoot)$(OSPlatformConfig)/</TestArchiveTestsDir>
6+
7+
<!-- handle different path to middleware in Helix -->
8+
<_TestEchoMiddleware Condition="'$(ContinuousIntegrationBuild)' == 'true' and '$(OS)' == 'Windows_NT'">%HELIX_CORRELATION_PAYLOAD%/xharness/TestEchoMiddleware</_TestEchoMiddleware>
9+
<_TestEchoMiddleware Condition="'$(ContinuousIntegrationBuild)' == 'true' and '$(OS)' != 'Windows_NT'">$HELIX_CORRELATION_PAYLOAD/xharness/TestEchoMiddleware</_TestEchoMiddleware>
10+
<_TestEchoMiddleware Condition="'$(ContinuousIntegrationBuild)' != 'true'">$(ArtifactsDir)bin/NetCoreServer/$(NetCoreAppCurrent)-$(Configuration)</_TestEchoMiddleware>
11+
12+
<WasmXHarnessArgs>$(WasmXHarnessArgs) --web-server-use-cors --web-server-use-https</WasmXHarnessArgs>
13+
<WasmXHarnessArgs>$(WasmXHarnessArgs) --set-web-server-http-env=DOTNET_TEST_WEBSOCKETHOST,DOTNET_TEST_HTTPHOST</WasmXHarnessArgs>
14+
<WasmXHarnessArgs>$(WasmXHarnessArgs) --set-web-server-https-env=DOTNET_TEST_SECUREWEBSOCKETHOST,DOTNET_TEST_SECUREHTTPHOST,DOTNET_TEST_HTTP2HOST</WasmXHarnessArgs>
15+
<WasmXHarnessArgs>$(WasmXHarnessArgs) --web-server-middleware=$(_TestEchoMiddleware)/NetCoreServer.dll,GenericHandler</WasmXHarnessArgs>
16+
</PropertyGroup>
17+
</Project>

src/libraries/Common/tests/System/Net/Prerequisites/NetCoreServer/GenericHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class GenericHandler
1313
// Must have constructor with this signature, otherwise exception at run time.
1414
public GenericHandler(RequestDelegate next)
1515
{
16-
// This is an HTTP Handler, so no need to store next.
16+
// This catch all HTTP Handler, so no need to store next.
1717
}
1818

1919
public async Task Invoke(HttpContext context)

src/libraries/Common/tests/System/Net/Prerequisites/NetCoreServer/NetCoreServer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>$(AspNetCoreAppCurrent)</TargetFramework>
55
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
66
<OutputType>Exe</OutputType>
77
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>

src/libraries/Common/tests/System/Net/Prerequisites/NetCoreServer/Startup.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,20 @@ public class Startup
1111
{
1212
public void ConfigureServices(IServiceCollection services)
1313
{
14+
services.AddCors(o => o.AddPolicy("AnyCors", builder =>
15+
{
16+
builder.AllowAnyOrigin()
17+
.AllowAnyMethod()
18+
.AllowAnyHeader()
19+
.WithExposedHeaders("*")
20+
;
21+
}));
1422
}
1523

1624
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
1725
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
1826
{
27+
app.UseCors("AnyCors");
1928
app.UseWebSockets();
2029
app.UseGenericHandler();
2130
}

0 commit comments

Comments
 (0)