private async Task <RunSummary> RunIsolatedAsync() { IsolatedContext isolatedContext = null; TestCollectionScope scope; try { isolatedContext = new IsolatedContext(_appDomainFixtureTypes, Aggregator); scope = new TestCollectionScope(TestCollection, _meeMessageSinkWithEvents, isolatedContext, _dispositionTaskFactory, DiagnosticMessageSink); // owns the isolated instance } catch (Exception) { isolatedContext?.Dispose(); throw; } try { var remoteTestCases = isolatedContext.CreateRemoteTestCases(TestCases, _testCaseDeserializerArgs); var remoteCancellationTokenSource = isolatedContext.CreateRemoteCancellationTokenSource(CancellationTokenSource); var runnerArgs = new object[] { TestCollection, remoteTestCases, DiagnosticMessageSink, MessageBus, TestCaseOrderer.GetType(), remoteCancellationTokenSource, Aggregator.ToException() }; var runSummary = await isolatedContext.CreateRemoteInstanceAndRunAsync <RemoteTestCollectionRunner>(runnerArgs, RemoteTestCollectionRunner.MethodRunAsync); // now that the run summary is available schedule the disposition of the scope as soon as it is completed scope.DisposeOnCompletionAsync(CancellationTokenSource.Token); return(runSummary); } catch (Exception) { scope.Dispose(); throw; } }
protected virtual void Dispose(bool disposing) { if (disposing) { _finalEventRaised?.Dispose(); _isolatedContext?.Dispose(); } }