public async Task TestToDynamicThreadPool1() { await AsTask.ToDynamicThreadPool(); Console.WriteLine(AsTask.WhereAmI()); Assert.True(AsTask.IsDynamicThreadPool(), "This is not the DynamicThreadPool!"); }
public async Task TestDelayAwaiterDynamicThreadPool() { await AsTask.ToDynamicThreadPool(); var stopwatch = Stopwatch.StartNew(); await Task.Delay(100); stopwatch.Stop(); Assert.True(AsTask.IsDynamicThreadPool(), $"This is not the DynamicThreadPool: {AsTask.WhereAmI()}"); Console.WriteLine($"{nameof(stopwatch)} {stopwatch.ElapsedMilliseconds}ms == {AsTask.GetCurrentContextType()} awaiter 100ms"); Assert.True(stopwatch.ElapsedMilliseconds >= 80 && stopwatch.ElapsedMilliseconds <= 150); }
public async Task TestMoreSwitching() { for (var i = 0; i < 1000; i++) { await TestSwitchingToContexts(); } for (var i = 0; i < 1000; i++) { await AsTask.ToMainContext(); Assert.True(AsTask.IsMainContext()); } for (var i = 0; i < 1000; i++) { await AsTask.ToBackgroundContext(); Assert.True(AsTask.IsBackgroundContext()); } for (var i = 0; i < 1000; i++) { await AsTask.ToContext(_contextTests1Id); Assert.True(AsTask.IsThreadContext(_contextTests1Id)); } for (var i = 0; i < 1000; i++) { await AsTask.ToStaticThreadPool(); Assert.True(AsTask.IsStaticThreadPool()); } for (var i = 0; i < 1000; i++) { await AsTask.ToDynamicThreadPool(); Assert.True(AsTask.IsDynamicThreadPool()); } }