Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Feedback: removed code sharing and used reflaction
  • Loading branch information
ManickaP committed Apr 14, 2023
commit df7b54153667a137fa407754142c2788dbbe4ae0
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<!-- Shared production code -->
<ItemGroup>
<Compile Include="..\..\..\..\Common\src\System\Net\Logging\NetEventSource.Common.cs" Link="Common\System\Net\Logging\NetEventSource.Common.cs" />
<Compile Include="..\..\..\..\System.Net.Quic\src\System\Net\Quic\Internal\MsQuicApi.cs" Link="ProductionCode\System\Net\Quic\Internal\MsQuicApi.cs" />
<Compile Include="..\..\..\..\System.Net.Quic\src\System\Net\Quic\Internal\MsQuicSafeHandle.cs" Link="ProductionCode\System\Net\Quic\Internal\MsQuicSafeHandle.cs" />
<Compile Include="..\..\..\..\System.Net.Quic\src\System\Net\Quic\Interop\*.cs" Link="ProductionCode\System\Net\Quic\Interop\*.cs" />
<Compile Include="..\..\..\..\System.Net.Quic\src\System\Net\Quic\NetEventSource.Quic.cs" Link="ProductionCode\System\Net\Quic\NetEventSource.Quic.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="5.0.9" />
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using System.Net;
using HttpStress;
using System.Net.Quic;
using Microsoft.Quic;

[assembly:SupportedOSPlatform("windows")]
[assembly:SupportedOSPlatform("linux")]
Expand Down Expand Up @@ -162,6 +161,10 @@ private static async Task<ExitCode> Run(Configuration config)

string GetAssemblyInfo(Assembly assembly) => $"{assembly.Location}, modified {new FileInfo(assembly.Location).LastWriteTime}";


Type msQuicApi = typeof(QuicConnection).Assembly.GetType("System.Net.Quic.MsQuicApi")!;
(bool maxQueueWorkDelaySet, string msQuicLibraryVersion) = ((bool, string))msQuicApi.GetMethod("SetUpForTests", BindingFlags.NonPublic | BindingFlags.Static)!.Invoke(null, Array.Empty<object?>())!;

Console.WriteLine(" .NET Core: " + GetAssemblyInfo(typeof(object).Assembly));
Console.WriteLine(" ASP.NET Core: " + GetAssemblyInfo(typeof(WebHost).Assembly));
Console.WriteLine(" System.Net.Http: " + GetAssemblyInfo(typeof(System.Net.Http.HttpClient).Assembly));
Expand All @@ -174,26 +177,17 @@ private static async Task<ExitCode> Run(Configuration config)
Console.WriteLine(" Content Length: " + config.MaxContentLength);
Console.WriteLine(" HTTP Version: " + config.HttpVersion);
Console.WriteLine(" QUIC supported: " + (IsQuicSupported ? "yes" : "no"));
Console.WriteLine(" MsQuic Version: " + MsQuicApi.MsQuicLibraryVersion);
Console.WriteLine(" MsQuic Version: " + msQuicLibraryVersion);
Console.WriteLine(" Lifetime: " + (config.ConnectionLifetime.HasValue ? $"{config.ConnectionLifetime.Value.TotalMilliseconds}ms" : "(infinite)"));
Console.WriteLine(" Operations: " + string.Join(", ", usedClientOperations.Select(o => o.name)));
Console.WriteLine(" Random Seed: " + config.RandomSeed);
Console.WriteLine(" Cancellation: " + 100 * config.CancellationProbability + "%");
Console.WriteLine("Max Content Size: " + config.MaxContentLength);
Console.WriteLine("Query Parameters: " + config.MaxParameters);
Console.WriteLine();
if (config.HttpVersion == HttpVersion.Version30 && IsQuicSupported)
if (config.HttpVersion == HttpVersion.Version30 && IsQuicSupported && !maxQueueWorkDelaySet)
{
unsafe
{
QUIC_SETTINGS settings = default(QUIC_SETTINGS);
settings.IsSet.MaxWorkerQueueDelayUs = 1;
settings.MaxWorkerQueueDelayUs = 2_500_000u; // 2.5s, 10x the default
if (MsQuic.StatusFailed(MsQuicApi.Api.ApiTable->SetParam(null, MsQuic.QUIC_PARAM_GLOBAL_SETTINGS, (uint)sizeof(QUIC_SETTINGS), (byte*)&settings)))
{
Console.WriteLine($"Unable to set MsQuic MaxWorkerQueueDelayUs.");
}
}
Console.WriteLine($"Unable to set MsQuic MaxWorkerQueueDelayUs.");
}

StressServer? server = null;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ internal sealed unsafe partial class MsQuicApi
// Remove once fixed: https://github.com/mono/linker/issues/1660
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(MsQuicSafeHandle))]
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(MsQuicContextSafeHandle))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(MsQuicApi))]
private MsQuicApi(QUIC_API_TABLE* apiTable)
{
ApiTable = apiTable;
Expand Down Expand Up @@ -227,4 +228,19 @@ private static bool IsTls13Disabled(bool isServer)
#endif
return false;
}

// Do not change the name and signature without looking for textual occurrences!
// This method is invoked via reflection from QUIC functional and HTTP stress tests.
private static (bool, string) SetUpForTests()
Copy link
Contributor

@antonfirsov antonfirsov Apr 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely the easiest option to solve this problem, but I thought including test-only methods in production assemblies is no-go. Do we have any existing precedent in the BCL?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't thought about that, but I found this for example:

// For testing.
internal HPackDecoder(int maxDynamicTableSize, int maxHeadersLength, DynamicTable dynamicTable)

I can always go back to code sharing though and try to minimize the number of shared files, either with some some reflection, strategically placed #if and/or code stubs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HPack ctr is not "dead code" otherwise, because it's also being used by the public constructor above. For me having a private, test-only method is a good tradeoff, considering the maintenance burden that comes with other options, but we should stick to BCL guidance. @stephentoub is it ok to expose such methods?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combo of shared code + reflection is there. @antonfirsov could you look into copying the appropriate files in the docker container please?

{
if (!IsQuicSupported)
{
return (true, MsQuicLibraryVersion);
}

QUIC_SETTINGS settings = default(QUIC_SETTINGS);
settings.IsSet.MaxWorkerQueueDelayUs = 1;
settings.MaxWorkerQueueDelayUs = 2_500_000u; // 2.5s, 10x the default
return (StatusSucceeded(MsQuicApi.Api.ApiTable->SetParam(null, QUIC_PARAM_GLOBAL_SETTINGS, (uint)sizeof(QUIC_SETTINGS), (byte*)&settings)), MsQuicLibraryVersion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public async Task AcceptConnectionAsync_SlowOptionsCallback_TimesOut(bool useCan

// Connect attempt should be stopped with "UserCanceled".
var connectException = await Assert.ThrowsAsync<AuthenticationException>(async () => await connectTask);
Assert.Contains(TlsAlertMessage.UserCanceled.ToString(), connectException.Message);
Assert.Contains("UserCanceled", connectException.Message);
}

[Fact]
Expand Down Expand Up @@ -160,7 +160,7 @@ public async Task AcceptConnectionAsync_ListenerDisposed_Throws()

// Connect attempt should be stopped with "UserCanceled".
var connectException = await Assert.ThrowsAsync<AuthenticationException>(async () => await connectTask);
Assert.Contains(TlsAlertMessage.UserCanceled.ToString(), connectException.Message);
Assert.Contains("UserCanceled", connectException.Message);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
using Xunit.Abstractions;
using System.Diagnostics.Tracing;
using System.Net.Sockets;
using Microsoft.Quic;
using static Microsoft.Quic.MsQuic;
using System.Reflection;

namespace System.Net.Quic.Tests
{
Expand Down Expand Up @@ -44,17 +43,14 @@ public abstract class QuicTestBase : IDisposable

static unsafe QuicTestBase()
{
Console.WriteLine($"MsQuic {(IsSupported ? "supported" : "not supported")} and using '{MsQuicApi.MsQuicLibraryVersion}'.");
Type msQuicApi = typeof(QuicConnection).Assembly.GetType("System.Net.Quic.MsQuicApi");
(bool maxQueueWorkDelaySet, string msQuicLibraryVersion) = ((bool, string))msQuicApi.GetMethod("SetUpForTests", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, Array.Empty<object?>());

if (IsSupported)
Console.WriteLine($"MsQuic {(IsSupported ? "supported" : "not supported")} and using '{msQuicLibraryVersion}'.");

if (IsSupported && !maxQueueWorkDelaySet)
{
QUIC_SETTINGS settings = default(QUIC_SETTINGS);
settings.IsSet.MaxWorkerQueueDelayUs = 1;
settings.MaxWorkerQueueDelayUs = 2_500_000u; // 2.5s, 10x the default
if (StatusFailed(MsQuicApi.Api.ApiTable->SetParam(null, QUIC_PARAM_GLOBAL_SETTINGS, (uint)sizeof(QUIC_SETTINGS), (byte*)&settings)))
{
Console.WriteLine($"Unable to set MsQuic MaxWorkerQueueDelayUs.");
}
Console.WriteLine($"Unable to set MsQuic MaxWorkerQueueDelayUs.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,7 @@
</ItemGroup>
<!-- Shared production code -->
<ItemGroup>
<Compile Include="$(CommonPath)System\Net\Logging\NetEventSource.Common.cs" Link="Common\System\Net\Logging\NetEventSource.Common.cs" />
<Compile Include="..\..\src\System\Net\Quic\Internal\MsQuicApi.cs" Link="ProductionCode\System\Net\Quic\Internal\MsQuicApi.cs" />
<Compile Include="..\..\src\System\Net\Quic\Internal\MsQuicApi.NativeMethods.cs" Link="ProductionCode\System\Net\Quic\Internal\MsQuicApi.NativeMethods.cs" />
<Compile Include="..\..\src\System\Net\Quic\Internal\MsQuicSafeHandle.cs" Link="ProductionCode\System\Net\Quic\Internal\MsQuicSafeHandle.cs" />
<Compile Include="..\..\src\System\Net\Quic\Internal\ThrowHelper.cs" Link="ProductionCode\System\Net\Quic\Internal\ThrowHelper.cs" />
<Compile Include="..\..\src\System\Net\Quic\Interop\*.cs" Link="ProductionCode\System\Net\Quic\Interop\*.cs" />
<Compile Include="..\..\src\System\Net\Quic\NetEventSource.Quic.cs" Link="ProductionCode\System\Net\Quic\NetEventSource.Quic.cs" />
<Compile Include="..\..\src\System\Net\Quic\QuicDefaults.cs" Link="ProductionCode\System\Net\Quic\QuicDefaults.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Interop.Libraries.cs" Link="Common\Interop\Windows\Interop.Libraries.cs" Condition="'$(TargetPlatformIdentifier)' == 'windows'" />
<Compile Include="$(CommonPath)Interop\Linux\Interop.Libraries.cs" Link="Common\Interop\Linux\Interop.Libraries.cs" Condition="'$(TargetPlatformIdentifier)' == 'linux'" />
<Compile Include="$(CommonPath)Interop\OSX\Interop.Libraries.cs" Link="Common\Interop\OSX\Interop.Libraries.cs" Condition="'$(TargetPlatformIdentifier)' == 'osx'" />
<Compile Include="$(CommonPath)System\Net\Security\TlsAlertMessage.cs" Link="Common\System\Net\Security\TlsAlertMessage.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(CommonTestPath)StreamConformanceTests\StreamConformanceTests.csproj" />
Expand Down