public void TestContinuationTasks_DoNotCauseDeadlocks() { var dummyCommand = new DummyCommand(new HystrixCommandOptions() { GroupKey = HystrixCommandGroupKeyDefault.AsKey("foobar") }); var options = new HystrixThreadPoolOptions() { CoreSize = 2, MaxQueueSize = 2, QueueSizeRejectionThreshold = 2, AllowMaximumSizeToDivergeFromCoreSize = false, }; // Scheduler to test var scheduler = new HystrixQueuedTaskScheduler(options); TaskActionClass tc1 = new TaskActionClass(output, 1); TaskActionClass tc2 = new TaskActionClass(output, 2); TaskActionClass tc3 = new TaskActionClass(output, 3); TaskActionClass tc4 = new TaskActionClass(output, 4); Task <int> t1 = new Task <int>((o) => tc1.Run(o), dummyCommand, CancellationToken.None, TaskCreationOptions.LongRunning); Task <int> t2 = new Task <int>((o) => tc2.Run(o), dummyCommand, CancellationToken.None, TaskCreationOptions.LongRunning); Task <int> t3 = new Task <int>((o) => tc3.Run(o), dummyCommand, CancellationToken.None, TaskCreationOptions.LongRunning); Task <int> t4 = new Task <int>((o) => tc4.Run(o), dummyCommand, CancellationToken.None, TaskCreationOptions.LongRunning); // Fill up to CoreSize t1.Start(scheduler); t2.Start(scheduler); // Make sure they are running Thread.Sleep(500); // Fill up queue t3.Start(scheduler); t4.Start(scheduler); // Allow all tasks to finish and cause continuation tasks to be queued tc1.Stop = true; tc2.Stop = true; tc3.Stop = true; tc4.Stop = true; Thread.Sleep(1000); Assert.True(t1.IsCompleted); Assert.Equal(1, t1.Result); Assert.True(t2.IsCompleted); Assert.Equal(2, t2.Result); Assert.True(t3.IsCompleted); Assert.Equal(3, t3.Result); Assert.True(t4.IsCompleted); Assert.Equal(4, t4.Result); }
public void TestContinuationTasks_DoNotCauseDeadlocks() { var dummyCommand = new DummyCommand(new HystrixCommandOptions() { GroupKey = HystrixCommandGroupKeyDefault.AsKey("foobar") }); var options = new HystrixThreadPoolOptions() { CoreSize = 2, }; // Scheduler to test var scheduler = new HystrixSyncTaskScheduler(options); TaskActionClass tc1 = new TaskActionClass(output, 1); TaskActionClass tc2 = new TaskActionClass(output, 2); Task <int> t1 = new Task <int>((o) => tc1.Run(o), dummyCommand, CancellationToken.None, TaskCreationOptions.LongRunning); Task <int> t2 = new Task <int>((o) => tc2.Run(o), dummyCommand, CancellationToken.None, TaskCreationOptions.LongRunning); // Fill up to CoreSize t1.Start(scheduler); t2.Start(scheduler); // Make sure they are running Thread.Sleep(500); // Allow t1 task to finish and cause continuation task to be queued tc1.Stop = true; Thread.Sleep(1000); Assert.True(t1.IsCompleted); Assert.Equal(1, t1.Result); tc2.Stop = true; Thread.Sleep(1000); Assert.True(t2.IsCompleted); Assert.Equal(2, t2.Result); }