Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/MagicOnion.Internal/ServiceNameHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reflection;
using System.Reflection;

namespace MagicOnion.Internal;

Expand All @@ -7,7 +7,7 @@ internal static class ServiceNameHelper
/// <summary>
/// Resolves the gRPC service name for a given service interface type.
/// If the interface has a <see cref="ServiceNameAttribute"/>, its value is used.
/// Otherwise, the short type name (<see cref="Type.Name"/>) is used as the default.
/// Otherwise, the short type name is used as the default.
/// </summary>
/// <param name="serviceInterfaceType">The service interface type (e.g., IMyService).</param>
/// <returns>The resolved service name string.</returns>
Expand Down
6 changes: 3 additions & 3 deletions tests/MagicOnion.Client.Tests/StreamingHubTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,6 @@ static async Task CoreAsync()
public async Task ConnectAsync_Failure()
{
// Arrange
var disposed = false;
var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(10));
var helper = new StreamingHubClientTestHelper<IGreeterHub, IGreeterHubReceiver>(
factoryProvider: DynamicStreamingHubClientFactoryProvider.Instance,
Expand All @@ -765,7 +764,7 @@ public async Task ConnectAsync_CancellationToken_Timeout()
onResponseHeaderAsync: async metadata =>
{
// Simulate a long time to response
await Task.Delay(1500);
await Task.Delay(1500, TestContext.Current.CancellationToken);
},
onDuplexStreamingCallDisposeAction: () =>
{
Expand All @@ -777,7 +776,7 @@ public async Task ConnectAsync_CancellationToken_Timeout()
var begin = Stopwatch.GetTimestamp();
var ex = await Record.ExceptionAsync(async () => await helper.ConnectAsync(connectTimeout.Token));
var elapsed = Stopwatch.GetElapsedTime(begin);
await Task.Delay(2000); // Wait for the ConnectAsync to complete.
await Task.Delay(2000, TestContext.Current.CancellationToken); // Wait for the ConnectAsync to complete.

// Assert
Assert.IsType<OperationCanceledException>(ex);
Expand Down Expand Up @@ -819,6 +818,7 @@ public async Task ConnectAsync_CancellationToken_Timeout_On_FirstMoveNext()

// Assert
Assert.Equal(123, result);
Assert.True(disposed);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Concurrent;
using System.Collections.Concurrent;
using Grpc.Net.Client;
using MagicOnion.Client.DynamicClient;
using MagicOnion.Server.Hubs;
Expand Down Expand Up @@ -330,9 +330,9 @@ public async Task CancelPendingTasksOnDisconnect(TestStreamingHubClientFactory c

// Act
var task = client.Invoke_CancelPendingTasksOnDisconnect(useGroup: false);
await Task.Delay(150); // Give some time to process the request.
await Task.Delay(150, TestContext.Current.CancellationToken); // Give some time to process the request.
await client.DisposeAsync(); // Disconnect from the server.
await Task.Delay(1500); // Wait for the timeout of the hub method queue processing. (see: StreamingHub.RequestQueueShutdownTimeout)
await Task.Delay(1500, TestContext.Current.CancellationToken); // Wait for the timeout of the hub method queue processing. (see: StreamingHub.RequestQueueShutdownTimeout)

// Assert
Assert.Equal((nameof(IStreamingHubClientResultTestHubReceiver.Never), (FakeStreamingHubClientResultTestHubReceiver.ArgumentEmpty)), receiver.Received[0]);
Expand All @@ -353,9 +353,9 @@ public async Task CancelPendingTasksOnDisconnect_Group(TestStreamingHubClientFac

// Act
var task = client.Invoke_CancelPendingTasksOnDisconnect(useGroup: true);
await Task.Delay(150); // Give some time to process the request.
await Task.Delay(150, TestContext.Current.CancellationToken); // Give some time to process the request.
await client.DisposeAsync(); // Disconnect from the server.
await Task.Delay(1500); // Wait for the timeout of the hub method queue processing. (see: StreamingHub.RequestQueueShutdownTimeout)
await Task.Delay(1500, TestContext.Current.CancellationToken); // Wait for the timeout of the hub method queue processing. (see: StreamingHub.RequestQueueShutdownTimeout)

// Assert
Assert.Equal((nameof(IStreamingHubClientResultTestHubReceiver.Never), (FakeStreamingHubClientResultTestHubReceiver.ArgumentEmpty)), receiver.Received[0]);
Expand Down Expand Up @@ -576,7 +576,7 @@ public async Task Invoke_Parameter_Zero()
var result = await Client.Parameter_Zero();
Items.TryAdd(nameof(Invoke_Parameter_Zero), result);
}
catch (Exception e)
catch (Exception)
{
throw;
}
Expand Down
17 changes: 9 additions & 8 deletions tests/MagicOnion.Server.Tests/StreamingHubDisconnectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,20 @@ public async Task DisconnectWhileConsumingHubMethodQueue()
var channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() {HttpClient = httpClient});
var client = await StreamingHubClient.ConnectAsync<IStreamingHubDisconnectionTestHub, IStreamingHubDisconnectionTestHubReceiver>(
channel,
Substitute.For<IStreamingHubDisconnectionTestHubReceiver>());
Substitute.For<IStreamingHubDisconnectionTestHubReceiver>(),
cancellationToken: TestContext.Current.CancellationToken);

client.DoWorkAsync();
await Task.Delay(50);
client.DoWorkAsync(); // 150ms
client.DoWorkAsync(); // 250ms
client.DoWorkAsync(); // 350ms
_ = client.DoWorkAsync();
await Task.Delay(50, TestContext.Current.CancellationToken);
_ = client.DoWorkAsync(); // 150ms
_ = client.DoWorkAsync(); // 250ms
_ = client.DoWorkAsync(); // 350ms

await client.DisposeAsync();
channel.Dispose();
httpClient.Dispose();

await Task.Delay(500);
await Task.Delay(500, TestContext.Current.CancellationToken);

var logs = factory.Logs.GetSnapshot();
var doWorkAsyncCallCount = logs.Count(x => x.Message == "DoWorkAsync:Begin");
Expand All @@ -63,7 +64,7 @@ public class StreamingHubDisconnectionTestHub(ILogger<StreamingHubDisconnectionT
public async Task DoWorkAsync()
{
logger.LogInformation("DoWorkAsync:Begin");
await Task.Delay(100);
await Task.Delay(100, TestContext.Current.CancellationToken);
_ = this.Context.CallContext.GetHttpContext().Features;
logger.LogInformation("DoWorkAsync:Done");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,18 @@ public async Task ThrowOnDisconnect()
var channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() {HttpClient = httpClient});
var client = await StreamingHubClient.ConnectAsync<IStreamingHubThrowOnDisconnectTestHub, IStreamingHubThrowOnDisconnectTestHubReceiver>(
channel,
Substitute.For<IStreamingHubThrowOnDisconnectTestHubReceiver>());
Substitute.For<IStreamingHubThrowOnDisconnectTestHubReceiver>(),
cancellationToken: TestContext.Current.CancellationToken);

await client.DoWorkAsync();
await client.DisposeAsync();
channel.Dispose();
httpClient.Dispose();

await Task.Delay(100);
await Task.Delay(100, TestContext.Current.CancellationToken);

var logs = this.factory.Logs.GetSnapshot();
Assert.True(logs.Any(x => x.Message == "OnDisconnected"));
Assert.Contains(logs, x => x.Message == "OnDisconnected");
Assert.True(pendingTaskRegistry.IsDisposed);
}
}
Expand Down
Loading