public async Task Actor_Should_Return_Cancelled_Task_On_Any_Method_AfterCalling_IAsyncDisposable_DisposeAsync() { //arrange var dispclass = new DisposableClass(); var intface = _TaskPoolActorFactory.Build <IDummyInterface1>(dispclass); //act var task = intface.DoAsync(); var disp = GetFiber(intface) as IAsyncDisposable; await disp.DisposeAsync(); TaskCanceledException error = null; Task canc = null; try { canc = intface.DoAsync(); await canc; } catch (TaskCanceledException e) { error = e; } //assert error.Should().NotBeNull(); task.IsCompleted.Should().BeTrue(); canc.IsCanceled.Should().BeTrue(); }
public async Task Enqueue_Action_Should_Cancel_Not_Started_Task_When_OnDispose() { Task newTask = null, notstarted = null; var done = false; //arrange var target = GetSafeFiber(t => t.Priority = ThreadPriority.Highest); newTask = target.Enqueue(() => TaskFactory(3)); while (RunningThread == null) { Thread.Sleep(100); } await target.DisposeAsync(); notstarted = target.Enqueue(() => { done = true; }); await newTask; TaskCanceledException error = null; try { await notstarted; } catch (TaskCanceledException e) { error = e; } notstarted.IsCanceled.Should().BeTrue(); error.Should().NotBeNull(); done.Should().BeFalse(); }
public async Task Actor_IActorLifeCycle_Abort_Should_Cancel_Enqueued_Task() { //arrange var dispclass = new DisposableClass(); var intface = _Factory.Build <IDummyInterface1>(dispclass); Task Taskrunning = intface.DoAsync(), Takenqueued = intface.DoAsync(); Thread.Sleep(100); //act IActorCompleteLifeCycle disp = intface as IActorCompleteLifeCycle; await disp.Abort(); //assert TaskCanceledException error = null; try { await Takenqueued; } catch (TaskCanceledException e) { error = e; } //assert error.Should().NotBeNull(); Takenqueued.IsCanceled.Should().BeTrue(); }
public async Task Enqueue_Func_T_Should_Cancel_Task_When_On_Disposed_Queue() { MonoThreadedQueue queue = null; //arrange using (queue = new MonoThreadedQueue()) { var task = queue.Enqueue(() => TaskFactory()); } Func <int> func = () => { return(25); }; Task newesttask = queue.Enqueue(func); TaskCanceledException error = null; try { await newesttask; } catch (TaskCanceledException e) { error = e; } newesttask.IsCanceled.Should().BeTrue(); error.Should().NotBeNull(); }
public async Task Enqueue_Action_Should_Cancel_Task_When_On_Disposed_Queue() { MonoThreadedQueue queue = null; //arrange using (queue = new MonoThreadedQueue()) { var task = queue.Enqueue(() => TaskFactory()); } bool Done = false; Task newesttask = queue.Enqueue(() => { Done = true; }); TaskCanceledException error = null; try { await newesttask; } catch (TaskCanceledException e) { error = e; } newesttask.IsCanceled.Should().BeTrue(); error.Should().NotBeNull(); Done.Should().BeFalse(); }
public async Task Enqueue_Action_Should_Cancel_Not_Started_Task_When_OnDispose() { Task newTask = null, notstarted = null; bool Done = false; //arrange using (var target = new MonoThreadedQueue(t => t.Priority = ThreadPriority.Highest)) { newTask = target.Enqueue(() => TaskFactory(3)); while (_RunningThread == null) { Thread.Sleep(100); } notstarted = target.Enqueue(() => { Done = true; }); } await newTask; TaskCanceledException error = null; try { await notstarted; } catch (TaskCanceledException e) { error = e; } notstarted.IsCanceled.Should().BeTrue(); error.Should().NotBeNull(); Done.Should().BeFalse(); }
public void TaskCanceledException_TaskNull() { // Arrange // Act var ex = new TaskCanceledException(); // Assert var tce = ex.Should().BeOfType <TaskCanceledException>().Which; var exceptionDetails = ExtractExceptionDetails(LogAndDestructureException(tce)); Assert_ContainsPropertyWithValue(exceptionDetails, nameof(TaskCanceledException.Task), "null"); }
public void TaskCanceledException_TaskWithSomeCreationOptions_TheyAreDestructured() { // Arrange var task = new Task(() => { }, TaskCreationOptions.LongRunning | TaskCreationOptions.PreferFairness); // Act var ex = new TaskCanceledException(task); // Assert var tce = ex.Should().BeOfType <TaskCanceledException>().Which; var exceptionDetails = ExtractExceptionDetails(LogAndDestructureException(tce)); var taskProperty = ExtractProperty(exceptionDetails, nameof(TaskCanceledException.Task)); var taskPropertyObject = taskProperty.Value.Should().BeOfType <JObject>().Which; Assert_ContainsPropertyWithValue(taskPropertyObject, nameof(Task.CreationOptions), $"{nameof(TaskCreationOptions.PreferFairness)}, {nameof(TaskCreationOptions.LongRunning)}"); }
public void TaskCanceledException_SimplePropertiesAreAttached() { // Arrange this.cancellationTokenSource.Cancel(); var task = Task.FromCanceled(this.cancellationTokenSource.Token); // Act var ex = new TaskCanceledException(task); // Assert var tce = ex.Should().BeOfType <TaskCanceledException>().Which; var exceptionDetails = ExtractExceptionDetails(LogAndDestructureException(tce)); Assert_ContainsPropertyWithValue(exceptionDetails, nameof(TaskCanceledException.CancellationToken), "CancellationRequested: true"); var taskProperty = ExtractProperty(exceptionDetails, nameof(TaskCanceledException.Task)); var taskPropertyObject = taskProperty.Value.Should().BeOfType <JObject>().Which; Assert_ContainsPropertyWithValue(taskPropertyObject, nameof(Task.Status), nameof(TaskStatus.Canceled)); Assert_ContainsPropertyWithValue(taskPropertyObject, nameof(Task.CreationOptions), nameof(TaskCreationOptions.None)); }
public async Task Dispose_Enqueue_Items_Should_Return_Canceled_Task_After_Stoping_Queue() { //arrange var fiber = GetSafeFiber(); await fiber.DisposeAsync(); var done = false; TaskCanceledException error = null; try { await fiber.Enqueue(() => { done = true; }); } catch (TaskCanceledException e) { error = e; } error.Should().NotBeNull(); done.Should().BeFalse(); }
public async Task Enqueue_Func_T_Should_Cancel_Task_When_On_Disposed_Queue() { var fiber = GetSafeFiber(); var task = fiber.Enqueue(() => TaskFactory()); await fiber.DisposeAsync(); Func <int> func = () => 25; Task newesttask = fiber.Enqueue(func); TaskCanceledException error = null; try { await newesttask; } catch (TaskCanceledException e) { error = e; } newesttask.IsCanceled.Should().BeTrue(); error.Should().NotBeNull(); }
public async Task Enqueue_Task_Should_Cancel_Task_When_Added_On_Disposed_Queue() { //arrange var fiber = GetSafeFiber(); var task = fiber.Enqueue(() => TaskFactory()); await fiber.DisposeAsync(); var newesttask = fiber.Enqueue(() => TaskFactory()); TaskCanceledException error = null; try { await newesttask; } catch (TaskCanceledException e) { error = e; } newesttask.IsCanceled.Should().BeTrue(); error.Should().NotBeNull(); }
public async Task Dispose_Enqueue_Items_Should_Return_Canceled_Task_After_Stoping_Queue() { //arrange MonoThreadedQueue queue = new MonoThreadedQueue(); queue.Dispose(); bool Done = false; TaskCanceledException error = null; try { await queue.Enqueue(() => { Done = true; }); } catch (TaskCanceledException e) { error = e; } error.Should().NotBeNull(); Done.Should().BeFalse(); }
public async Task Enqueue_Action_Should_Cancel_Task_When_On_Disposed() { var fiber = GetSafeFiber(); var task = fiber.Enqueue(() => TaskFactory()); await fiber.DisposeAsync(); var done = false; var newesttask = fiber.Enqueue(() => { done = true; }); TaskCanceledException error = null; try { await newesttask; } catch (TaskCanceledException e) { error = e; } newesttask.IsCanceled.Should().BeTrue(); error.Should().NotBeNull(); done.Should().BeFalse(); }