public void NumberOfResultsIsConsistent(ViewDefinition defn) { const int cyclesCount = 5; using (var remoteViewClient = Context.ViewProcessor.CreateClient()) using (var mre = new ManualResetEvent(false)) { var cycles = new BlockingCollection <IEngineResourceReference <IViewCycle> >(); var listener = new EventViewResultListener(); listener.ProcessCompleted += delegate { mre.Set(); }; listener.ViewDefinitionCompilationFailed += delegate { mre.Set(); }; listener.CycleExecutionFailed += delegate { mre.Set(); }; listener.CycleCompleted += (sender, e) => { cycles.Add(remoteViewClient.CreateCycleReference(e.FullResult.ViewCycleId)); remoteViewClient.TriggerCycle(); }; remoteViewClient.SetResultListener(listener); remoteViewClient.SetViewCycleAccessSupported(true); var sequence = ArbitraryViewCycleExecutionSequence.Create(Enumerable.Range(0, cyclesCount).Select(i => DateTimeOffset.Now + TimeSpan.FromHours(i))); var options = new ExecutionOptions(sequence, ViewExecutionFlags.TriggersEnabled | ViewExecutionFlags.AwaitMarketData, null, new ViewCycleExecutionOptions(default(DateTimeOffset), ExecutionOptions.GetDefaultMarketDataSpec())); remoteViewClient.AttachToViewProcess(defn.UniqueID, options); TimeSpan timeout = TimeSpan.FromMinutes(5); if (!mre.WaitOne(timeout)) { throw new TimeoutException(string.Format("Failed to get result in {0}", timeout)); } Assert.Equal(cyclesCount, cycles.Count); var specs = cycles.Select(GetAllSpecs).ToList(); var inconsistent = specs.Zip(specs.Skip(1), Tuple.Create).SelectMany( t => { var diff = new HashSet <Tuple <string, ValueSpecification> >(t.Item1); diff.SymmetricExceptWith(t.Item2); return(diff); }).Distinct(); if (inconsistent.Any()) { var counts = string.Join(",", specs.Select(c => c.Count.ToString())); var inconsistentStrings = specs.Select(s => string.Join(",", s.Where(x => inconsistent.Contains(x)).Select(x => x.ToString()))); string inconsistentString = string.Join(Environment.NewLine, inconsistentStrings); throw new Exception(string.Format("Inconsistent number of results for {0} {1}: {2}", defn.Name, counts, inconsistentString)); } } }