public async Task RemoveGroupAsyncForConnectionOnDifferentServerWorks() { var manager1 = new RedisHubLifetimeManager <MyHub>(new LoggerFactory().CreateLogger <RedisHubLifetimeManager <MyHub> >(), Options.Create(new RedisOptions() { Factory = t => new TestConnectionMultiplexer() })); var manager2 = new RedisHubLifetimeManager <MyHub>(new LoggerFactory().CreateLogger <RedisHubLifetimeManager <MyHub> >(), Options.Create(new RedisOptions() { Factory = t => new TestConnectionMultiplexer() })); using (var client = new TestClient()) { var connection = HubConnectionContextUtils.Create(client.Connection); await manager1.OnConnectedAsync(connection).OrTimeout(); await manager1.AddGroupAsync(connection.ConnectionId, "name").OrTimeout(); await manager2.InvokeGroupAsync("name", "Hello", new object[] { "World" }).OrTimeout(); await AssertMessageAsync(client); await manager2.RemoveGroupAsync(connection.ConnectionId, "name").OrTimeout(); await manager2.InvokeGroupAsync("name", "Hello", new object[] { "World" }).OrTimeout(); await connection.DisposeAsync().OrTimeout(); Assert.Null(client.TryRead()); } }
public async Task RemoveGroupAsyncForConnectionOnDifferentServerWorks() { var manager1 = new RedisHubLifetimeManager <MyHub>(new LoggerFactory().CreateLogger <RedisHubLifetimeManager <MyHub> >(), Options.Create(new RedisOptions() { Factory = t => new TestConnectionMultiplexer() })); var manager2 = new RedisHubLifetimeManager <MyHub>(new LoggerFactory().CreateLogger <RedisHubLifetimeManager <MyHub> >(), Options.Create(new RedisOptions() { Factory = t => new TestConnectionMultiplexer() })); using (var client = new TestClient()) { var output = Channel.CreateUnbounded <HubMessage>(); var connection = new HubConnectionContext(output, client.Connection); await manager1.OnConnectedAsync(connection).OrTimeout(); await manager1.AddGroupAsync(connection.ConnectionId, "name").OrTimeout(); await manager2.InvokeGroupAsync("name", "Hello", new object[] { "World" }).OrTimeout(); AssertMessage(output); await manager2.RemoveGroupAsync(connection.ConnectionId, "name").OrTimeout(); await manager2.InvokeGroupAsync("name", "Hello", new object[] { "World" }).OrTimeout(); Assert.False(output.In.TryRead(out var item)); } }
public async Task WritingToGroupWithOneConnectionFailingSecondConnectionStillReceivesMessage() { var manager = new RedisHubLifetimeManager<MyHub>(new LoggerFactory().CreateLogger<RedisHubLifetimeManager<MyHub>>(), Options.Create(new RedisOptions() { Factory = t => new TestConnectionMultiplexer() })); using (var client1 = new TestClient()) using (var client2 = new TestClient()) { // Force an exception when writing to connection var writer = new Mock<ChannelWriter<HubMessage>>(); writer.Setup(o => o.WaitToWriteAsync(It.IsAny<CancellationToken>())).Throws(new Exception()); var connection1 = HubConnectionContextUtils.Create(client1.Connection, new MockChannel(writer.Object)); var connection2 = HubConnectionContextUtils.Create(client2.Connection); await manager.OnConnectedAsync(connection1).OrTimeout(); await manager.AddGroupAsync(connection1.ConnectionId, "group"); await manager.OnConnectedAsync(connection2).OrTimeout(); await manager.AddGroupAsync(connection2.ConnectionId, "group"); await manager.InvokeGroupAsync("group", "Hello", new object[] { "World" }).OrTimeout(); // connection1 will throw when receiving a group message, we are making sure other connections // are not affected by another connection throwing await AssertMessageAsync(client2); // Repeat to check that group can still be sent to await manager.InvokeGroupAsync("group", "Hello", new object[] { "World" }).OrTimeout(); await AssertMessageAsync(client2); } }
public async Task InvokeGroupAsyncWritesToAllConnectionsInGroupOutput() { using (var client1 = new TestClient()) using (var client2 = new TestClient()) { var manager = new RedisHubLifetimeManager <MyHub>(new LoggerFactory().CreateLogger <RedisHubLifetimeManager <MyHub> >(), Options.Create(new RedisOptions() { Factory = t => new TestConnectionMultiplexer() })); var connection1 = HubConnectionContextUtils.Create(client1.Connection); var connection2 = HubConnectionContextUtils.Create(client2.Connection); await manager.OnConnectedAsync(connection1).OrTimeout(); await manager.OnConnectedAsync(connection2).OrTimeout(); await manager.AddGroupAsync(connection1.ConnectionId, "gunit").OrTimeout(); await manager.InvokeGroupAsync("gunit", "Hello", new object[] { "World" }).OrTimeout(); await AssertMessageAsync(client1); await connection1.DisposeAsync().OrTimeout(); await connection2.DisposeAsync().OrTimeout(); Assert.Null(client2.TryRead()); } }
public async Task InvokeGroupAsyncOnServerWithoutConnectionWritesOutputToGroupConnection() { var manager1 = new RedisHubLifetimeManager <MyHub>(new LoggerFactory().CreateLogger <RedisHubLifetimeManager <MyHub> >(), Options.Create(new RedisOptions() { Factory = t => new TestConnectionMultiplexer() })); var manager2 = new RedisHubLifetimeManager <MyHub>(new LoggerFactory().CreateLogger <RedisHubLifetimeManager <MyHub> >(), Options.Create(new RedisOptions() { Factory = t => new TestConnectionMultiplexer() })); using (var client = new TestClient()) { var connection = HubConnectionContextUtils.Create(client.Connection); await manager1.OnConnectedAsync(connection).OrTimeout(); await manager1.AddGroupAsync(connection.ConnectionId, "name").OrTimeout(); await manager2.InvokeGroupAsync("name", "Hello", new object[] { "World" }).OrTimeout(); await AssertMessageAsync(client); } }
public async Task InvokeGroupAsyncWritesToAllConnectionsInGroupOutput() { using (var client1 = new TestClient()) using (var client2 = new TestClient()) { var output1 = Channel.CreateUnbounded <HubMessage>(); var output2 = Channel.CreateUnbounded <HubMessage>(); var manager = new RedisHubLifetimeManager <MyHub>(new LoggerFactory().CreateLogger <RedisHubLifetimeManager <MyHub> >(), Options.Create(new RedisOptions() { Factory = t => new TestConnectionMultiplexer() })); var connection1 = new HubConnectionContext(output1, client1.Connection); var connection2 = new HubConnectionContext(output2, client2.Connection); await manager.OnConnectedAsync(connection1).OrTimeout(); await manager.OnConnectedAsync(connection2).OrTimeout(); await manager.AddGroupAsync(connection1.ConnectionId, "gunit").OrTimeout(); await manager.InvokeGroupAsync("gunit", "Hello", new object[] { "World" }).OrTimeout(); AssertMessage(output1); Assert.False(output2.In.TryRead(out var item)); } }