public async Task SendGroupAsyncWillCancelWithToken()
        {
            using (var client1 = new TestClient(pauseWriterThreshold: 2))
            {
                var manager     = CreateNewHubLifetimeManager();
                var connection1 = HubConnectionContextUtils.Create(client1.Connection);
                await manager.OnConnectedAsync(connection1).OrTimeout();

                await manager.AddToGroupAsync(connection1.ConnectionId, "group").OrTimeout();

                var cts      = new CancellationTokenSource();
                var sendTask = manager.SendGroupAsync("group", "Hello", new object[] { "World" }, cts.Token).OrTimeout();
                Assert.False(sendTask.IsCompleted);
                cts.Cancel();
                await sendTask.OrTimeout();

                var tcs = new TaskCompletionSource <object>(TaskCreationOptions.RunContinuationsAsynchronously);
                connection1.ConnectionAborted.Register(t =>
                {
                    ((TaskCompletionSource <object>)t).SetResult(null);
                }, tcs);
                await tcs.Task.OrTimeout();
            }
        }
        public async Task SendGroupAsyncWritesToAllConnectionsInGroupOutput()
        {
            using (var client1 = new TestClient())
            using (var client2 = new TestClient())
            {
                var manager = new DefaultHubLifetimeManager<MyHub>(new Logger<DefaultHubLifetimeManager<MyHub>>(NullLoggerFactory.Instance));
                var connection1 = HubConnectionContextUtils.Create(client1.Connection);
                var connection2 = HubConnectionContextUtils.Create(client2.Connection);

                await manager.OnConnectedAsync(connection1).OrTimeout();
                await manager.OnConnectedAsync(connection2).OrTimeout();

                await manager.AddToGroupAsync(connection1.ConnectionId, "gunit").OrTimeout();

                await manager.SendGroupAsync("gunit", "Hello", new object[] { "World" }).OrTimeout();

                var message = Assert.IsType<InvocationMessage>(client1.TryRead());
                Assert.Equal("Hello", message.Target);
                Assert.Single(message.Arguments);
                Assert.Equal("World", (string)message.Arguments[0]);

                Assert.Null(client2.TryRead());
            }
        }