示例#1
0
        private void VerifyWaitForTimerFired(
            DurableTimer durableTimer,
            TimeSpan durationSeconds,
            bool expectedWaitForStop,
            Action action
            )
        {
            var delayBeforeStopping = durationSeconds;

            // action() call may block until Stop is invoked from another thread.
            var thread = new Thread(() =>
            {
                Thread.Sleep(delayBeforeStopping);
                durableTimer.Stop();
            });

            thread.Start();
            try
            {
                var elapsedMilliseconds = DurableTestUtilities.MeasureExecutionTimeInMilliseconds(action);

                // Check if CreateTimerOrContinue was actually blocked
                if (expectedWaitForStop)
                {
                    Assert.True(elapsedMilliseconds > delayBeforeStopping.TotalMilliseconds * 0.8);
                }
                else
                {
                    Assert.True(elapsedMilliseconds < delayBeforeStopping.TotalMilliseconds * 0.2);
                }
            }
            finally
            {
                thread.Join();
            }
        }
示例#2
0
 private void EmulateStop(DurableTimer durableTimer)
 {
     durableTimer.Stop();
 }