public void DisconnectRemoteObjectsAfterCrossDomainCallsOnDispose() { // Arrange var prefix = Guid.NewGuid().ToString(); var cde = new CountdownEvent(2); var tracker = new InMemoryRemoteObjectTracker(cde, prefix); TrackingServices.RegisterTrackingHandler(tracker); // Set the minimum permissions needed to run code in the new AppDomain PermissionSet permSet = new PermissionSet(PermissionState.None); permSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution)); var remote = AppDomain.CreateDomain("Remote", null, AppDomain.CurrentDomain.SetupInformation, permSet); // Act try { using (_tracer.StartActive($"{prefix}test-span")) { remote.DoCallBack(AppDomainHelpers.EmptyCallback); using (_tracer.StartActive($"{prefix}test-span-inner")) { remote.DoCallBack(AppDomainHelpers.EmptyCallback); } } } finally { AppDomain.Unload(remote); } // Ensure that we wait long enough for the lease manager poll to occur. // Even though we reset LifetimeServices.LeaseManagerPollTime to a shorter duration, // the default value is 10 seconds so the first poll may not be affected by our modification bool eventSet = cde.Wait(TimeSpan.FromSeconds(30)); // Assert Assert.True(eventSet); Assert.Equal(2, tracker.DisconnectCount); }
public void DisconnectRemoteObjectsAfterCrossDomainCallsOnDispose() { // Arrange var cde = new CountdownEvent(2); var tracker = new InMemoryRemoteObjectTracker(cde); TrackingServices.RegisterTrackingHandler(tracker); var remote = AppDomain.CreateDomain("Remote", null, AppDomain.CurrentDomain.SetupInformation); // Act try { using (_tracer.StartActive("test-span")) { remote.DoCallBack(EmptyCallback); using (_tracer.StartActive("test-span-inner")) { remote.DoCallBack(EmptyCallback); } } } finally { AppDomain.Unload(remote); } // Ensure that we wait long enough for the lease manager poll to occur. // Even though we reset LifetimeServices.LeaseManagerPollTime to a shorter duration, // the default value is 10 seconds so the first poll may not be affected by our modification bool eventSet = cde.Wait(TimeSpan.FromSeconds(30)); // Assert Assert.True(eventSet); Assert.Equal(2, tracker.DisconnectCount); }