コード例 #1
0
        public void ZeroTimeoutDoesNotStartAsyncAction()
        {
            bool _hasRun = false;

            Assert.Throws <SyntheticTimeoutException>(() =>
            {
                FusionCacheExecutionUtils.RunAsyncActionWithTimeout(async ct => { _hasRun = true; }, TimeSpan.Zero, false, t => { });
            });
            Assert.False(_hasRun);
        }
コード例 #2
0
        public void DoNotCancelWhenTimeoutActuallyWorks()
        {
            var factoryCompleted = false;
            var timeoutMs        = 500;
            var innerDelayMs     = 2_000;

            Assert.ThrowsAny <TimeoutException>(() =>
            {
                FusionCacheExecutionUtils.RunAsyncActionWithTimeout(async ct => { await Task.Delay(innerDelayMs); ct.ThrowIfCancellationRequested(); factoryCompleted = true; }, TimeSpan.FromMilliseconds(timeoutMs), false);
            });
            Thread.Sleep(innerDelayMs);

            Assert.True(factoryCompleted);
        }