public void HangReportNotSuppressedOnLongRunningTaskCancelled() { this.Factory.HangDetectionTimeout = TimeSpan.FromMilliseconds(10); var hangReported = new AsyncManualResetEvent(); this.Context.OnReportHang = (hangDuration, iterations, id) => hangReported.Set(); var cancellationSource = new CancellationTokenSource(); JoinableTask?task = this.Factory.RunAsync( async() => { await Task.Delay(40, cancellationSource.Token); }, JoinableTaskCreationOptions.LongRunning); var taskCollection = new JoinableTaskCollection(this.Factory.Context); taskCollection.Add(task); this.Factory.Run( async() => { using (JoinableTaskCollection.JoinRelease tempJoin = taskCollection.Join()) { cancellationSource.Cancel(); await task.JoinAsync().NoThrowAwaitable(); await hangReported.WaitAsync().WithTimeout(UnexpectedTimeout); } }); }
public void HangReportNotSuppressedOnLongRunningTaskCompleted() { this.Factory.HangDetectionTimeout = TimeSpan.FromMilliseconds(10); var hangReported = new AsyncManualResetEvent(); this.Context.OnReportHang = (hangDuration, iterations, id) => hangReported.Set(); JoinableTask?task = this.Factory.RunAsync( async() => { await Task.Delay(30); }, JoinableTaskCreationOptions.LongRunning); task.Join(); Assert.False(hangReported.IsSet); var taskCollection = new JoinableTaskCollection(this.Factory.Context); taskCollection.Add(task); this.Factory.Run( async() => { using (JoinableTaskCollection.JoinRelease tempJoin = taskCollection.Join()) { await hangReported.WaitAsync().WithTimeout(UnexpectedTimeout); } }); }