private static IObservable <PerfTestResult> CreateRunObservable(TestSuiteInfo testSuiteInfo, Predicate <TestInfo> testFilter, Action <ExperimentProcess> startProcess, PerfTestConfiguration configuration, bool parallel = false) { return(Observable.Create <PerfTestResult>( observer => { var assemblyLocation = BuildTestSuiteAssembly(testSuiteInfo); var processes = new MultiExperimentProcess( (from testMethod in testSuiteInfo.Tests where testFilter(testMethod) select new ExperimentProcess( string.Format( "{0}.{1}({2})", testSuiteInfo.TesterType.Name, testMethod.TestMethodName, testMethod.TestedType.Name), assemblyLocation, TestSuiteCodeBuilder.TestSuiteClassName, testSuiteInfo.TesterType, testMethod.TestedType, testMethod.TestMethodName, configuration)).ToArray()); var listeners = Observable.Empty <PerfTestResult>(); if (!parallel) { listeners = processes.Experiments.Aggregate(listeners, (current, experiment) => current.Concat( new SingleExperimentListener(experiment, startProcess))); } else { listeners = from experiment in processes.Experiments.ToObservable() from result in new SingleExperimentListener(experiment, startProcess) select result; } IDisposable subscription = null; subscription = listeners.SubscribeSafe(observer); return Disposable.Create( () => { if (subscription != null) { subscription.Dispose(); subscription = null; } processes.Dispose(); if (!string.IsNullOrEmpty(assemblyLocation)) { File.Delete(assemblyLocation); } }); })); }
private static IObservable<PerfTestResult> CreateRunObservable(TestSuiteInfo testSuiteInfo, Predicate<TestInfo> testFilter, Action<ExperimentProcess> startProcess, PerfTestConfiguration configuration, bool parallel = false) { return Observable.Create<PerfTestResult>( observer => { var assemblyLocation = BuildTestSuiteAssembly(testSuiteInfo); var processes = new MultiExperimentProcess( (from testMethod in testSuiteInfo.Tests where testFilter(testMethod) select new ExperimentProcess( string.Format( "{0}.{1}({2})", testSuiteInfo.TesterType.Name, testMethod.TestMethodName, testMethod.TestedType.Name), assemblyLocation, TestSuiteCodeBuilder.TestSuiteClassName, testSuiteInfo.TesterType, testMethod.TestedType, testMethod.TestMethodName, configuration)).ToArray()); var listeners = Observable.Empty<PerfTestResult>(); if (!parallel) { listeners = processes.Experiments.Aggregate(listeners, (current, experiment) => current.Concat( new SingleExperimentListener(experiment, startProcess))); } else { listeners = from experiment in processes.Experiments.ToObservable() from result in new SingleExperimentListener(experiment, startProcess) select result; } IDisposable subscription = null; subscription = listeners.SubscribeSafe(observer); return Disposable.Create( () => { if (subscription != null) { subscription.Dispose(); subscription = null; } processes.Dispose(); if (!string.IsNullOrEmpty(assemblyLocation)) { File.Delete(assemblyLocation); } }); }); }