Esempio n. 1
0
        private async Task YieldTwoActivitiesDeep(ActivityEventSource es)
        {
            Assert.Equal(Guid.Empty, EventSource.CurrentThreadActivityId);
            es.ExampleStart();
            es.Example2Start();
            await Task.Yield();

            es.Example2Stop();
            es.ExampleStop();
            Assert.Equal(Guid.Empty, EventSource.CurrentThreadActivityId);
        }
Esempio n. 2
0
        public void StartStopCreatesActivity()
        {
            using ActivityEventListener l = new ActivityEventListener();
            using ActivityEventSource es  = new ActivityEventSource();

            Assert.Equal(Guid.Empty, EventSource.CurrentThreadActivityId);
            es.ExampleStart();
            Assert.NotEqual(Guid.Empty, EventSource.CurrentThreadActivityId);
            es.ExampleStop();
            Assert.Equal(Guid.Empty, EventSource.CurrentThreadActivityId);
        }
Esempio n. 3
0
        public async Task ActivityFlowsAsync()
        {
            using ActivityEventListener l = new ActivityEventListener();
            using ActivityEventSource es  = new ActivityEventSource();

            Assert.Equal(Guid.Empty, EventSource.CurrentThreadActivityId);
            es.ExampleStart();
            Assert.NotEqual(Guid.Empty, EventSource.CurrentThreadActivityId);
            await Task.Yield();

            Assert.NotEqual(Guid.Empty, EventSource.CurrentThreadActivityId);
            es.ExampleStop();
            Assert.Equal(Guid.Empty, EventSource.CurrentThreadActivityId);
        }
Esempio n. 4
0
        public async Task ActivityIdIsZeroedOnThreadSwitchOut()
        {
            using ActivityEventListener l = new ActivityEventListener();
            using ActivityEventSource es  = new ActivityEventSource();

            // Run tasks on many threads. If an activity id leaks it is likely
            // that the thread will be sheduled to run one of our other tasks
            // and we can detect the non-zero id at the start of the task
            List <Task> tasks = new List <Task>();

            for (int i = 0; i < 100; i++)
            {
                tasks.Add(Task.Run(() => YieldTwoActivitiesDeep(es)));
            }

            await Task.WhenAll(tasks.ToArray());
        }
Esempio n. 5
0
        public async Task SetCurrentActivityIdBeforeEventFlowsAsync()
        {
            using ActivityEventListener l = new ActivityEventListener();
            using ActivityEventSource es  = new ActivityEventSource();
            try
            {
                Guid g = Guid.NewGuid();
                EventSource.SetCurrentThreadActivityId(g);
                Assert.Equal(g, EventSource.CurrentThreadActivityId);
                es.ExampleStart();
                await Task.Yield();

                es.ExampleStop();
                Assert.Equal(g, EventSource.CurrentThreadActivityId);
            }
            finally
            {
                EventSource.SetCurrentThreadActivityId(Guid.Empty);
            }
        }