Beispiel #1
0
        public void ParallelRequestsWithTracing()
        {
            var setupLog     = new SetupLog();
            var stringWriter = new StringWriter();

            using (TestServer testServer = CreateTestServer(stringWriter, setupLog))
            {
                // 10 parallel threads, each thread issues 2 requests, each request traces 2x
                Action issueRequestAction = () =>
                {
                    IssueTraceRequest(testServer, 2);
                    IssueTraceRequest(testServer, 2);
                };
                Parallel.Invoke(Enumerable.Repeat(issueRequestAction, 10).ToArray());
            }

            string logOutput = stringWriter.ToString();

            testOutputHelper.WriteLine(logOutput);

            int countLineBreaks = TestHelper.CountLineBreaks(logOutput);

            Assert.True(countLineBreaks > 140 && countLineBreaks < 180);

            Assert.NotEmpty(setupLog);
            Assert.False(setupLog.HasAnyExceeding(TraceLevel.Info));
        }
Beispiel #2
0
        //[InlineData(40, 1000, 30)]
        public void ParallelTraceTest(int threads, int requestsPerThread, int tracesPerRequest)
        {
            var       setupLog         = new SetupLog();
            Stopwatch overallStopwatch = Stopwatch.StartNew();

            // Test logging to TextWriter.Null - which should have no perf overhead
            using (TestServer testServer = CreateTestServer(TextWriter.Null, setupLog))
            {
                Action testThread = () =>
                {
                    int threadId = Thread.CurrentThread.ManagedThreadId;
                    testOutputHelper.WriteLine("{0}: Starting requests on thread {1}", overallStopwatch.Elapsed, threadId);
                    var stopWatch = Stopwatch.StartNew();

                    for (int i = 0; i < requestsPerThread; ++i)
                    {
                        IssueTraceRequest(testServer, tracesPerRequest);
                    }
                    stopWatch.Stop();

                    testOutputHelper.WriteLine("{0}: Completed {1} requests on thread {2} in {3}",
                                               overallStopwatch.Elapsed,
                                               requestsPerThread,
                                               threadId,
                                               stopWatch.Elapsed);
                };

                Parallel.Invoke(Enumerable.Repeat(testThread, threads).ToArray());
            }

            Assert.NotEmpty(setupLog);
            Assert.False(setupLog.HasAnyExceeding(TraceLevel.Info));
        }
Beispiel #3
0
        public void SingleRequestWithTracing()
        {
            var setupLog     = new SetupLog();
            var stringWriter = new StringWriter();

            using (TestServer testServer = CreateTestServer(stringWriter, setupLog))
            {
                IssueTraceRequest(testServer, 2);
            }

            testOutputHelper.WriteLine(stringWriter.ToString());

            Assert.NotEmpty(setupLog);
            Assert.False(setupLog.HasAnyExceeding(TraceLevel.Info));
        }
Beispiel #4
0
        public void ExceptionTracing()
        {
            var setupLog     = new SetupLog();
            var stringWriter = new StringWriter();

            using (TestServer testServer = CreateTestServer(stringWriter, setupLog))
            {
                var task     = testServer.CreateRequest("/exception").GetAsync();
                var response = task.Result; // Wait for the call to complete
            }

            testOutputHelper.WriteLine(stringWriter.ToString());

            Assert.NotEmpty(setupLog);
            Assert.False(setupLog.HasAnyExceeding(TraceLevel.Info));
        }
Beispiel #5
0
        public void SingleRequestWithTracingWith3LogTargets()
        {
            var setupLog     = new SetupLog();
            var stringWriter = new StringWriter();

            using (TestServer testServer = new OwinTestWith3LogTargets(testOutputHelper).CreateTestServer(stringWriter, setupLog, true))
            {
                IssueTraceRequest(testServer, 2);
            }
            testOutputHelper.WriteLine("Logging complete.");

            testOutputHelper.WriteLine("");
            testOutputHelper.WriteLine("StringWriter contents:");
            testOutputHelper.WriteLine(stringWriter.ToString());

            Assert.NotEmpty(setupLog);

            testOutputHelper.WriteLine("");
            testOutputHelper.WriteLine("Setup log:");
            testOutputHelper.WriteEntries(setupLog);
            Assert.False(setupLog.HasAnyExceeding(TraceLevel.Info));
        }