public async Task OnConnectionAsync(ConnectionContext context)
        {
            // In theory, we could do some witchcraft here and NOT adapt the connection
            // by default, only actually adapting it when the event source is enabled
            // (observable via OnEventCommand in the EventSource itself)
            // That would mean that connections running prior to starting the trace wouldn't
            // be traced though.
            // But it may be closer to what we'd do if this was integrated into Kestrel itself.

            _eventSource.StartConnection(context.ConnectionId);

            var oldTransport = context.Transport;

            try
            {
                await using var tracingPipe = new TracingPipe(context.Transport, _eventSource, context.ConnectionId);
                context.Transport           = tracingPipe;
                await _next(context);
            }
            finally
            {
                context.Transport = oldTransport;
                _eventSource.EndConnection(context.ConnectionId);
            }
        }
Exemple #2
0
 public void CreatePipeline()
 {
     this.currentNode          = new TracingPipe();
     this.downstreamSegment    = new TracingPipe();
     this.downstreamForwarding = new ForwardingSegment(this.downstreamSegment);
     this.testSubject          = new ForwardingSegment(this.currentNode);
     this.testSubject.ChainTo(this.downstreamForwarding);
 }
Exemple #3
0
        private void ExceptionCallsResetForForwardCallsWithoutArgs(TracingPipe pipe)
        {
            pipe.CallAdded = (t, c) => this.DoWhenCall(endFigure, c, () => { throw new InvalidOperationException(); });
            var       coordinateSystem = CoordinateSystem.DefaultGeography;
            Exception ex = SpatialTestUtils.RunCatching(() => this.testSubject.GeographyPipeline.EndFigure());

            Assert.IsInstanceOfType(ex, typeof(InvalidOperationException), "got the exception we threw");
            StringAssert.Contains(ex.StackTrace, "DoWhenCall", "Lost the original stack trace");

            AssertResetCalledLastOnCurrentAndDownstream();
        }
Exemple #4
0
        private void ExceptionCallsResetForForwardCallsWithArgs(TracingPipe pipe)
        {
            pipe.CallAdded = (t, c) => this.DoWhenNotCall(resetCall, c, () => { throw new InvalidOperationException(); });
            var       coordinateSystem = CoordinateSystem.DefaultGeography;
            Exception ex = SpatialTestUtils.RunCatching(() => this.testSubject.GeographyPipeline.SetCoordinateSystem(coordinateSystem));

            Assert.True(ex.GetType() == typeof(InvalidOperationException), "got the exception we threw");
            Assert.True(ex.StackTrace.Contains("DoWhenNotCall"), "Lost the original stack trace");

            AssertResetCalledLastOnCurrentAndDownstream();
        }
Exemple #5
0
        private void ExceptionCallsResetForForwardCallsWithoutArgs(TracingPipe pipe)
        {
            pipe.CallAdded = (t, c) => this.DoWhenCall(endFigure, c, () => { throw new InvalidOperationException(); });
            var       coordinateSystem = CoordinateSystem.DefaultGeography;
            Exception ex = SpatialTestUtils.RunCatching(() => this.testSubject.GeographyPipeline.EndFigure());

            Assert.True(ex.GetType() == typeof(InvalidOperationException), "got the exception we threw");

#if !NETCOREAPP1_1 && !NETCOREAPP2_1 && !NETCOREAPP3_1
            // .NET Core does not appear to generate this stack trace
            Assert.True(ex.StackTrace.Contains("DoWhenCall"), "Lost the original stack trace");
#endif
            AssertResetCalledLastOnCurrentAndDownstream();
        }
Exemple #6
0
 public MPipe(TracingPipe tracingPipe)
 {
     this.tracingPipe = tracingPipe;
 }