Skip to content

Commit

Permalink
ClientSubscription potential fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lilla28 committed Apr 21, 2023
1 parent 31fa211 commit 181bc05
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static ProcessExplorerBuilder UseGrpc(

builder.ServiceCollection.AddGrpc();

builder.ServiceCollection.TryAddSingleton<GrpcListenerService>();
builder.ServiceCollection.AddSingleton<GrpcListenerService>();
builder.ServiceCollection.AddSingleton<IHostedService>(provider => provider.GetRequiredService<GrpcListenerService>());
builder.ServiceCollection.AddSingleton<ProcessExplorerServer>(provider => provider.GetRequiredService<GrpcListenerService>());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

namespace ProcessExplorer.Server.IntegrationTests;

[Collection("EndToEndTestsCollection")]
public class EndToEndTests : IAsyncLifetime
{
private IHost? _host;
Expand All @@ -51,7 +50,7 @@ public async Task Client_can_connect()

var messages = new List<Message>();

var call = client.Subscribe(new Empty(), cancellationToken: cancellationTokenSource.Token);
using var call = client.Subscribe(new Empty(), cancellationToken: cancellationTokenSource.Token);

// We want to receive the message, that the subscription is established, and we do not want to wait.
// Due to that no processes/subsystems/runtime information have not been declared it will just receive the subscription alive notification
Expand Down Expand Up @@ -101,9 +100,9 @@ public async Task Client_can_subscribe_and_receive_messages()
var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(2));
var messages = new List<Message>();

var call = client.Subscribe(new Empty(), cancellationToken: cancellationTokenSource.Token);
using var call = client.Subscribe(new Empty(), cancellationToken: cancellationTokenSource.Token);

//try catch block to avoid OperationCanceledException due to that we are just waiting for 1 second
//try catch block to avoid OperationCanceledException due to that we are just waiting for 2 seconds
try
{
await foreach (var message in call.ResponseStream.ReadAllAsync())
Expand Down

0 comments on commit 181bc05

Please sign in to comment.