public void GetHangReportWithActualHang() { var endTestTokenSource = new CancellationTokenSource(); this.Context.OnReportHang = (hangDuration, iterations, id) => { IHangReportContributor contributor = this.Context; var report = contributor.GetHangReport(); this.Logger.WriteLine(report.Content); endTestTokenSource.Cancel(); this.Context.OnReportHang = null; }; this.Factory.HangDetectionTimeout = TimeSpan.FromMilliseconds(10); Assert.Throws <OperationCanceledException>(delegate { this.Factory.Run(delegate { using (this.Context.SuppressRelevance()) { return(Task.Run(async delegate { await this.Factory.RunAsync(async delegate { await this.Factory.SwitchToMainThreadAsync(endTestTokenSource.Token); }); })); } }); }); }
protected int GetPendingTasksCount() { IHangReportContributor hangContributor = this.context; var contribution = hangContributor.GetHangReport(); var dgml = XDocument.Parse(contribution.Content); return(dgml.Descendants(XName.Get("Node", DgmlNamespace)).Count(n => n.Attributes("Category").Any(c => c.Value == "Task"))); }
public void GetHangReportSimple() { IHangReportContributor contributor = this.Context; var report = contributor.GetHangReport(); Assert.Equal("application/xml", report.ContentType); Assert.NotNull(report.ContentName); this.Logger.WriteLine(report.Content); var dgml = XDocument.Parse(report.Content); Assert.Equal("DirectedGraph", dgml.Root.Name.LocalName); Assert.Equal("http://schemas.microsoft.com/vs/2009/dgml", dgml.Root.Name.Namespace); }
public void GetHangReportProducesDgmlWithNamedJoinableCollections() { const string jtcName = "My Collection"; this.joinableCollection !.DisplayName = jtcName; this.Factory.RunAsync(delegate { IHangReportContributor contributor = this.Context; HangReportContribution?report = contributor.GetHangReport(); this.Logger.WriteLine(report.Content); var dgml = XDocument.Parse(report.Content); IEnumerable <string>?collectionLabels = from node in dgml.Root !.Element(XName.Get("Nodes", DgmlNamespace)) !.Elements() where node.Attribute(XName.Get("Category"))?.Value == "Collection" select node.Attribute(XName.Get("Label"))?.Value; Assert.Contains(collectionLabels, label => label == jtcName); return(Task.CompletedTask); });
public void GetHangReportProducesDgmlWithMethodNameYieldingOnMainThread() { this.ExecuteOnDispatcher(async delegate { var messagePosted = new AsyncManualResetEvent(); var nowait = Task.Run(async delegate { await this.Factory.SwitchToMainThreadAsync(); var nowait2 = this.YieldingMethodAsync(); messagePosted.Set(); }); await messagePosted.WaitAsync(); IHangReportContributor contributor = this.Context; var report = contributor.GetHangReport(); this.Logger.WriteLine(report.Content); var dgml = XDocument.Parse(report.Content); var collectionLabels = from node in dgml.Root.Element(XName.Get("Nodes", DgmlNamespace)).Elements() where node.Attribute(XName.Get("Category"))?.Value == "Task" select node.Attribute(XName.Get("Label"))?.Value; Assert.True(collectionLabels.Any(label => label.Contains(nameof(this.YieldingMethodAsync)))); }); }
public void GetHangReportProducesDgmlWithMethodNameRequestingMainThread() { var mainThreadRequested = new ManualResetEventSlim(); Task.Run(delegate { var awaiter = this.Factory.SwitchToMainThreadAsync().GetAwaiter(); awaiter.OnCompleted(delegate { /* this anonymous delegate is expected to include the name of its containing method */ }); mainThreadRequested.Set(); }); mainThreadRequested.Wait(); IHangReportContributor contributor = this.Context; var report = contributor.GetHangReport(); this.Logger.WriteLine(report.Content); var dgml = XDocument.Parse(report.Content); var collectionLabels = from node in dgml.Root.Element(XName.Get("Nodes", DgmlNamespace)).Elements() where node.Attribute(XName.Get("Category"))?.Value == "Task" select node.Attribute(XName.Get("Label"))?.Value; Assert.True(collectionLabels.Any(label => label.Contains(nameof(this.GetHangReportProducesDgmlWithMethodNameRequestingMainThread)))); }