Exemplo n.º 1
0
        public async Task WaitForConnection(TestContext ctx, CancellationToken cancellationToken)
        {
            var serverTask = WaitForServerConnection(ctx, cancellationToken);
            var clientTask = WaitForClientConnection(ctx, cancellationToken);

            var t1 = clientTask.ContinueWith(t => {
                if (t.IsFaulted || t.IsCanceled)
                {
                    Server.Dispose();
                }
            });
            var t2 = serverTask.ContinueWith(t => {
                if (t.IsFaulted || t.IsCanceled)
                {
                    Client.Dispose();
                }
            });

            try {
                await Task.WhenAll(serverTask, clientTask, t1, t2);
            } catch (ConnectionFinishedException) {
                throw;
            } catch (Exception ex) {
                Exception error = null;
                TestContext.AddException(ref error, clientTask);
                TestContext.AddException(ref error, serverTask);
                if (error == null)
                {
                    error = ex;
                }
                throw error;
            }
        }
Exemplo n.º 2
0
        void OnAccepted(Task <HttpConnection> task)
        {
            if (task.IsCanceled || cts.IsCancellationRequested)
            {
                OnFinished();
                return;
            }
            if (task.IsFaulted)
            {
                TestContext.AddException(ref currentError, task);
                return;
            }

            Listen();

            var connection = task.Result;

            MainLoop(connection, cts.Token).ContinueWith(t => {
                TestContext.LogDebug(5, "MAIN LOOP DONE: {0} {1}", this, t.Status);
                if (t.IsFaulted)
                {
                    TestContext.AddException(ref currentError, t);
                }
                if (t.IsCompleted)
                {
                    connection.Dispose();
                }

                OnFinished();
            });
        }