Skip to content

Commit

Permalink
Upgrade to more 8.0 packages and code analyzers
Browse files Browse the repository at this point in the history
  • Loading branch information
menees committed Oct 27, 2024
1 parent 738bddf commit cdfb1c6
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 50 deletions.
3 changes: 2 additions & 1 deletion Remoting.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
LICENSE = LICENSE
NuGet.Config = NuGet.Config
README.md = README.md
testEnvironments.json = testEnvironments.json
.github\workflows\windows.yml = .github\workflows\windows.yml
EndProjectSection
EndProject
Expand All @@ -32,7 +33,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Menees.Remoting.Tests", "te
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Menees.Remoting.TestHost", "tests\Menees.Remoting.TestHost\Menees.Remoting.TestHost.csproj", "{A454B747-CAAA-4F97-89D7-996381D5E25C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Menees.Remoting.TestClient", "tests\Menees.Remoting.TestClient\Menees.Remoting.TestClient.csproj", "{A1DEDBCB-2AA9-4288-8427-9EF357BAF663}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Menees.Remoting.TestClient", "tests\Menees.Remoting.TestClient\Menees.Remoting.TestClient.csproj", "{A1DEDBCB-2AA9-4288-8427-9EF357BAF663}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
6 changes: 4 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

<!-- Note: We can't target .NET Standard 2.0 because DispatchProxy.Create isn't supported there (due to lack of Reflection.Emit). -->
<!-- https://docs.microsoft.com/en-us/dotnet/standard/frameworks -->
<MeneesTargetNetFramework>net48</MeneesTargetNetFramework>
<MeneesTargetNetFramework></MeneesTargetNetFramework>
<!-- DOTNET_VERSION: Update .NET target version. -->
<MeneesTargetNetCoreBase>net8.0</MeneesTargetNetCoreBase>
<TargetFrameworks>$(MeneesTargetNetCoreBase);$(MeneesTargetNetFramework)</TargetFrameworks>

Expand Down Expand Up @@ -81,7 +82,8 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
<!-- DOTNET_VERSION: Keep NetAnalyzers in sync with current .NET version. -->
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
5 changes: 1 addition & 4 deletions src/Menees.Remoting/ClientProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ internal void Initialize(RmiClient<TServiceInterface> client)
throw new InvalidOperationException("Client proxy was not initialized.");
}

if (targetMethod == null)
{
throw new ArgumentNullException(nameof(targetMethod));
}
ArgumentNullException.ThrowIfNull(targetMethod);

// This requires a synchronous call from the client to avoid deadlocks since DispatchProxy.Invoke is synchronous.
object? result = this.client.Invoke(targetMethod, args ?? []);
Expand Down
4 changes: 2 additions & 2 deletions src/Menees.Remoting/Menees.Remoting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Text.Json" Version="6.0.10" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.4" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
</ItemGroup>

<Choose>
Expand Down
5 changes: 1 addition & 4 deletions src/Menees.Remoting/MessageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ public MessageClient(
public MessageClient(ClientSettings settings)
: base(settings)
{
if (settings == null)
{
throw new ArgumentNullException(nameof(settings));
}
ArgumentNullException.ThrowIfNull(settings);

this.ConnectTimeout = settings.ConnectTimeout;
this.pipe = new(settings.ServerPath, settings.ServerHost, this, (PipeClientSecurity?)settings.Security);
Expand Down
5 changes: 1 addition & 4 deletions src/Menees.Remoting/MessageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ public MessageServer(Func<TIn, Task<TOut>> requestHandler, ServerSettings settin
public MessageServer(Func<TIn, CancellationToken, Task<TOut>> requestHandler, ServerSettings settings)
: base(settings)
{
if (settings == null)
{
throw new ArgumentNullException(nameof(settings));
}
ArgumentNullException.ThrowIfNull(settings);

this.requestHandler = requestHandler ?? throw new ArgumentNullException(nameof(requestHandler));

Expand Down
7 changes: 5 additions & 2 deletions src/Menees.Remoting/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ protected virtual void Dispose(bool disposing)
#region Private Types

private sealed class ScopedLogger<TScope> : ILogger
where TScope : notnull
{
#region Private Data Members

Expand All @@ -137,7 +138,9 @@ public ScopedLogger(ILogger logger, TScope scope)

#region Public Methods

public IDisposable BeginScope<TState>(TState state) => this.logger.BeginScope(state);
public IDisposable? BeginScope<TState>(TState state)
where TState : notnull
=> this.logger.BeginScope(state);

public bool IsEnabled(LogLevel logLevel) => this.logger.IsEnabled(logLevel);

Expand All @@ -150,7 +153,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
// call context wrapped around one or more local ILogger.Log calls with no intervening Task.Runs or awaits.
// To avoid having to do BeginScope around all our Log calls, it's easier to make this wrapper class that does it.
// https://stackoverflow.com/questions/63851259/since-iloggert-is-a-singleton-how-different-threads-can-use-beginscope-with#comment128022925_63852241
using IDisposable logScope = this.BeginScope(this.scope);
using IDisposable? logScope = this.BeginScope(this.scope);
this.logger.Log(logLevel, eventId, state, exception, formatter);
}

Expand Down
5 changes: 1 addition & 4 deletions src/Menees.Remoting/RmiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ public RmiClient(
public RmiClient(ClientSettings settings)
: base(settings)
{
if (settings == null)
{
throw new ArgumentNullException(nameof(settings));
}
ArgumentNullException.ThrowIfNull(settings);

this.ConnectTimeout = settings.ConnectTimeout;
this.pipe = new(settings.ServerPath, settings.ServerHost, this, (PipeClientSecurity?)settings.Security);
Expand Down
5 changes: 1 addition & 4 deletions src/Menees.Remoting/RmiServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ public RmiServer(
public RmiServer(TServiceInterface serviceInstance, ServerSettings settings)
: base(settings)
{
if (settings == null)
{
throw new ArgumentNullException(nameof(settings));
}
ArgumentNullException.ThrowIfNull(settings);

this.serviceInstance = serviceInstance ?? throw new ArgumentNullException(nameof(serviceInstance));

Expand Down
10 changes: 2 additions & 8 deletions src/Menees.Remoting/ServerHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ public void Dispose()
/// <exception cref="InvalidOperationException">If <see cref="IServerHost.Exit"/> has started already.</exception>
public void Add(IServer server)
{
if (server == null)
{
throw new ArgumentNullException(nameof(server));
}
ArgumentNullException.ThrowIfNull(server);

this.EnsureReady();

Expand Down Expand Up @@ -209,10 +206,7 @@ private void Dispose(bool disposing)

private void EnsureReady([CallerMemberName] string? callerMemberName = null)
{
if (this.isDisposed)
{
throw new ObjectDisposedException(nameof(ServerHost));
}
ObjectDisposedException.ThrowIf(this.isDisposed, this);

if (this.isExiting)
{
Expand Down
8 changes: 3 additions & 5 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
</PropertyGroup>

<ItemGroup Condition="$(IsUnitTestProject)">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="MSTest" Version="3.6.1" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Shouldly" Version="4.0.3" />
<PackageReference Include="Shouldly" Version="4.2.1" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
</ItemGroup>
</Project>
7 changes: 3 additions & 4 deletions tests/Menees.Remoting.Tests/BaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#endregion

[TestClass]
#pragma warning disable MSTEST0016 // Test class should have test method. This is used as a base class with init and cleanup.
public class BaseTests
#pragma warning restore MSTEST0016 // Test class should have test method
{
#region Private Data Members

Expand Down Expand Up @@ -70,10 +72,7 @@ protected static Task TestCrossProcessClientAsync(int clientCount, string server

protected string GenerateServerPath([CallerMemberName] string? callerMemberName = null)
{
if (callerMemberName == null)
{
throw new ArgumentNullException(nameof(callerMemberName));
}
ArgumentNullException.ThrowIfNull(callerMemberName);

string result = $"{this.GetType().FullName}.{callerMemberName}";
return result;
Expand Down
16 changes: 13 additions & 3 deletions tests/Menees.Remoting.Tests/RmiServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ public void CloneString()
actual.ShouldBe(expected);
}

[TestMethod]
public void OneShot()
{
// Run 1 client with a single server listener.
this.TestClient(1, 1, 1);
}

[TestMethod]
public void SingleServer()
{
Expand Down Expand Up @@ -222,17 +229,19 @@ private void TestClient(

// Make sure all the servers have completely exited in case another TestClient
// starts up immediately using the same serverPath. We don't want a new client
// to race in an grab an old server listener just as its shutting down.
// to race in and grab an old server listener just as its shutting down.
((IServerHost)host).Exit();
host.WaitForExit();
}

private void TestClient(int clientCount, string serverPath, ClientSecurity? clientSecurity = null)
{
TimeSpan timeout = Debugger.IsAttached ? Timeout.InfiniteTimeSpan : ClientSettings.DefaultConnectTimeout;
ParallelOptions parallelOptions = new() { MaxDegreeOfParallelism = Math.Min(clientCount, 8 * Environment.ProcessorCount) };
int[] source = [.. Enumerable.Range(1, clientCount)];
Parallel.ForEach(
Enumerable.Range(1, clientCount),
new ParallelOptions { MaxDegreeOfParallelism = Math.Min(clientCount, 8 * Environment.ProcessorCount) },
source,
parallelOptions,
item =>
{
ClientSettings clientSettings = new(serverPath)
Expand All @@ -242,6 +251,7 @@ private void TestClient(int clientCount, string serverPath, ClientSecurity? clie
Security = clientSecurity,
};

Debug.WriteLine($"Testing client {item}");
using RmiClient<ITester> client = new(clientSettings);
ITester proxy = client.CreateProxy();
TestProxy(proxy, item, isSingleClient: clientCount == 1);
Expand Down

0 comments on commit cdfb1c6

Please sign in to comment.