public static async Task RunSessionAsync(AppFunc app,
            Func<Http2ClientSession, Http2ServerSession, Task> sessionOperations)
        {
            DuplexStream clientStream = new DuplexStream();
            DuplexStream serverStream = clientStream.GetOpositeStream();

            Task clientTask, serverTask;
            using (Http2ClientSession clientSession = new Http2ClientSession(clientStream, false, CancellationToken.None, CancellationToken.None))
            {
                using (Http2ServerSession serverSession = new Http2ServerSession(app, new TransportInformation()))
                {
                    clientTask = clientSession.Start();
                    serverTask = serverSession.Start(serverStream, CancellationToken.None);

                    await sessionOperations(clientSession, serverSession);
                }
            }

            await clientTask;
            await serverTask;
        }
        public void ConnectionReset_StreamsAborted()
        {
            DuplexStream clientStream = new DuplexStream();
            DuplexStream serverStream = clientStream.GetOpositeStream();
            ManualResetEvent waitForRequest = new ManualResetEvent(false);
            ManualResetEvent waitForCancel = new ManualResetEvent(false);

            AppFunc app = environment =>
                {
                    OwinResponse response = new OwinResponse(environment);
                    TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
                    response.CallCancelled.Register(() =>
                    {
                        waitForCancel.Set();
                        tcs.TrySetCanceled();
                    });
                    waitForRequest.Set();
                    return tcs.Task;
                };

            Task clientTask, serverTask;
            using (Http2ClientSession clientSession = new Http2ClientSession(clientStream, false, CancellationToken.None, CancellationToken.None))
            {
                using (Http2ServerSession serverSession = new Http2ServerSession(app, CreateTransportInfo()))
                {
                    clientTask = clientSession.Start();
                    serverTask = serverSession.Start(serverStream, CancellationToken.None);

                    IList<KeyValuePair<string, string>> requestPairs = GenerateHeaders("GET");
                    Http2ClientStream clientProtocolStream = clientSession.SendRequest(requestPairs, null, 3, false, CancellationToken.None);
                    Task<IList<KeyValuePair<string, string>>> responseTask = clientProtocolStream.GetResponseAsync();
                    waitForRequest.WaitOne();

                    clientStream.Abort();

                    Assert.Throws<AggregateException>(() => responseTask.Result);
                    Assert.Throws<AggregateException>(() => clientTask.Wait(1000));
                    Assert.True(serverTask.Wait(1000));
                    Assert.True(waitForCancel.WaitOne(1000));
                }
            }
        }