コード例 #1
0
        public void TestSoftTimeout_ExceptionThrownOnStop()
        {
            var timeout = TimeSpan.FromMilliseconds(50);

            using (var target = new RpcApplicationContext(timeout, null))
                using (var cancellationEvent = new ManualResetEventSlim())
                {
                    var message = Guid.NewGuid().ToString();
                    RpcApplicationContext.SetCurrent(target);
#pragma warning disable 0618
                    target.DebugSoftTimeout += (sender, e) => cancellationEvent.Set();
#pragma warning restore 0618
                    target.CancellationToken.Register(() =>
                    {
                        throw new Exception(message);
                    }
                                                      );
                    target.StartTimeoutWatch();
                    Assert.That(target.CancellationToken.WaitHandle.WaitOne(TimeSpan.FromSeconds(1)));
                    // Mono sets WaitHandle eagerly (CLR might set after callback)
                    Assert.That(cancellationEvent.Wait(TimeSpan.FromSeconds(1)));
                    Assert.That(RpcApplicationContext.IsCanceled);
                    var exception = Assert.Throws <AggregateException>(() => target.StopTimeoutWatch());
                    Assert.That(exception.InnerException.Message, Is.EqualTo(message));
                }
        }
コード例 #2
0
		public void TestSoftTimeout_ExceptionThrownOnStop()
		{
			var timeout = TimeSpan.FromMilliseconds( 50 );
			using ( var target = new RpcApplicationContext( timeout, null ) )
			using ( var cancellationEvent = new ManualResetEventSlim() )
			{
				var message = Guid.NewGuid().ToString();
				RpcApplicationContext.SetCurrent( target );
#pragma warning disable 0618
				target.DebugSoftTimeout += ( sender, e ) => cancellationEvent.Set();
#pragma warning restore 0618
				target.CancellationToken.Register( () =>
					{
						throw new Exception( message );
					}
				);
				target.StartTimeoutWatch();
				Assert.That( target.CancellationToken.WaitHandle.WaitOne( TimeSpan.FromSeconds( 1 ) ) );
				// Mono sets WaitHandle eagerly (CLR might set after callback)
				Assert.That( cancellationEvent.Wait( TimeSpan.FromSeconds( 1 ) ) );
				Assert.That( RpcApplicationContext.IsCanceled );
				var exception = Assert.Throws<AggregateException>( () => target.StopTimeoutWatch() );
				Assert.That( exception.InnerException.Message, Is.EqualTo( message ) );
			}
		}
コード例 #3
0
		public void TestSoftTimeout_Stoped_Never()
		{
			var timeout = TimeSpan.FromMilliseconds( 50 );
			using ( var target = new RpcApplicationContext( timeout, null ) )
			{
				RpcApplicationContext.SetCurrent( target );
				target.StartTimeoutWatch();
				target.StopTimeoutWatch();
				Assert.That( target.CancellationToken.WaitHandle.WaitOne( TimeSpan.FromMilliseconds( timeout.TotalMilliseconds * 2 ) ), Is.False );
				Assert.That( RpcApplicationContext.IsCanceled, Is.False );
			}
		}
コード例 #4
0
        public void TestSoftTimeout_Stoped_Never()
        {
            var timeout = TimeSpan.FromMilliseconds(50);

            using (var target = new RpcApplicationContext(timeout, null))
            {
                RpcApplicationContext.SetCurrent(target);
                target.StartTimeoutWatch();
                target.StopTimeoutWatch();
                Assert.That(target.CancellationToken.WaitHandle.WaitOne(TimeSpan.FromMilliseconds(timeout.TotalMilliseconds * 2)), Is.False);
                Assert.That(RpcApplicationContext.IsCanceled, Is.False);
            }
        }
コード例 #5
0
        public void TestHardTimeout_Stopped_Never()
        {
            var timeout = TimeSpan.FromMilliseconds(20);

            using (var waitHandle = new ManualResetEventSlim())
                using (var target = new RpcApplicationContext(timeout, timeout))
                {
                    RpcApplicationContext.SetCurrent(target);
                    target.StartTimeoutWatch();
                    target.CancellationToken.Register(() => waitHandle.Set());

                    Assert.That(waitHandle.Wait(TimeSpan.FromSeconds(1)));
                    target.StopTimeoutWatch();
                    Thread.Sleep(TimeSpan.FromMilliseconds(timeout.TotalMilliseconds * 2));

                    Assert.That(RpcApplicationContext.IsCanceled);
                }
        }
コード例 #6
0
		public void TestHardTimeout_Stopped_Never()
		{
			var timeout = TimeSpan.FromMilliseconds( 20 );
			using ( var waitHandle = new ManualResetEventSlim() )
			using ( var target = new RpcApplicationContext( timeout, timeout ) )
			{
				RpcApplicationContext.SetCurrent( target );
				target.StartTimeoutWatch();
				target.CancellationToken.Register( () => waitHandle.Set() );

				Assert.That( waitHandle.Wait( TimeSpan.FromSeconds( 1 ) ) );
				target.StopTimeoutWatch();
				Thread.Sleep( TimeSpan.FromMilliseconds( timeout.TotalMilliseconds * 2 ) );

				Assert.That( RpcApplicationContext.IsCanceled );
			}
		}