Ejemplo n.º 1
0
        public async Task DisconnectRemoteObjectsAfterCrossDomainCallsOnDispose()
        {
            var tracker = new InMemoryRemoteObjectTracker();

            TrackingServices.RegisterTrackingHandler(tracker);

            var remote = AppDomain.CreateDomain("Remote", null, AppDomain.CurrentDomain.SetupInformation);

            try
            {
                using (LogContext.PushProperty("Prop1", 42))
                {
                    remote.DoCallBack(CallFromRemote);

                    using (LogContext.PushProperty("Prop2", 24))
                    {
                        remote.DoCallBack(CallFromRemote);
                    }
                }
            }
            finally
            {
                AppDomain.Unload(remote);
            }

            await Task.Delay(200);

            // This is intermittently 2 or 3 (now, 4), depending on the moods of the test runner;
            // I think "at least two" is what we're concerned about, here.
            Assert.InRange(tracker.DisconnectCount, 2, 4);

            void CallFromRemote()
            {
            }
        }
Ejemplo n.º 2
0
        public async Task DisconnectRemoteObjectsAfterCrossDomainCallsOnDispose()
        {
            // Arrange
            var tracker = new InMemoryRemoteObjectTracker();

            TrackingServices.RegisterTrackingHandler(tracker);

            var remote = AppDomain.CreateDomain("Remote", null, AppDomain.CurrentDomain.SetupInformation);

            // Act
            try
            {
                using (LogContext.PushProperty("Prop1", 42))
                {
                    remote.DoCallBack(CallFromRemote);

                    using (LogContext.PushProperty("Prop2", 24))
                    {
                        remote.DoCallBack(CallFromRemote);
                    }
                }
            }
            finally
            {
                AppDomain.Unload(remote);
            }

            await Task.Delay(200);

            // Assert
            Assert.Equal(2, tracker.DisconnectCount);

            void CallFromRemote()
            {
            }
        }