示例#1
0
		public void TestConstructor_IsTimeoutFalse()
		{
			using ( var target = new TimeoutWatcher() )
			{
				Assert.That( target.IsTimeout, Is.False );
			}
		}
 public void TestConstructor_IsTimeoutFalse()
 {
     using (var target = new TimeoutWatcher())
     {
         Assert.That(target.IsTimeout, Is.False);
     }
 }
示例#3
0
		public void TestStart_Timeout_TimeoutEventOccurred_IsTimeoutToBeTrue()
		{
			using ( var target = new TimeoutWatcher() )
			using ( var waitHandle = new ManualResetEventSlim() )
			{
				target.Timeout += ( sender, e ) => waitHandle.Set();
				target.Start( _timeout );
				Assert.That( waitHandle.Wait( TimeSpan.FromSeconds( 1 ) ) );
				Assert.That( target.IsTimeout );
			}
		}
 public void TestStart_Timeout_TimeoutEventOccurred_IsTimeoutToBeTrue()
 {
     using (var target = new TimeoutWatcher())
         using (var waitHandle = new ManualResetEventSlim())
         {
             target.Timeout += (sender, e) => waitHandle.Set();
             target.Start(_timeout);
             Assert.That(waitHandle.Wait(TimeSpan.FromSeconds(1)));
             Assert.That(target.IsTimeout);
         }
 }
示例#5
0
		public void TestStart_StoppedTimeout_TimeoutEventNotOccurred_IsTimeoutToBeFalse()
		{
			using ( var target = new TimeoutWatcher() )
			using ( var waitHandle = new ManualResetEventSlim() )
			{
				target.Timeout += ( sender, e ) => waitHandle.Set();
				target.Start( _timeout );
				target.Stop();
				Assert.That( waitHandle.Wait( ( int )( _timeout.TotalMilliseconds * 2 ) ), Is.False );
				Assert.That( target.IsTimeout, Is.False );
			}
		}
 public void TestStop_AfterTimeout_Harmless()
 {
     using (var target = new TimeoutWatcher())
         using (var waitHandle = new ManualResetEventSlim())
         {
             target.Timeout += (sender, e) => waitHandle.Set();
             target.Start(_timeout);
             Assert.That(waitHandle.Wait(TimeSpan.FromSeconds(1)));
             target.Stop();
             Assert.That(target.IsTimeout, Is.True);
         }
 }
 public void TestStart_StoppedTimeout_TimeoutEventNotOccurred_IsTimeoutToBeFalse()
 {
     using (var target = new TimeoutWatcher())
         using (var waitHandle = new ManualResetEventSlim())
         {
             target.Timeout += (sender, e) => waitHandle.Set();
             target.Start(_timeout);
             target.Stop();
             Assert.That(waitHandle.Wait(( int )(_timeout.TotalMilliseconds * 2)), Is.False);
             Assert.That(target.IsTimeout, Is.False);
         }
 }
示例#8
0
		public void TestStop_Twise_Harmless()
		{
			using ( var target = new TimeoutWatcher() )
			using ( var waitHandle = new ManualResetEventSlim() )
			{
				target.Timeout += ( sender, e ) => waitHandle.Set();
				target.Start( _timeout );
				target.Stop();
				Assert.That( waitHandle.Wait( ( int )( _timeout.TotalMilliseconds * 2 ) ), Is.False );
				target.Stop();
				Assert.That( target.IsTimeout, Is.False );
			}
		}
 public void TestReset_NotTimeout_Harmless()
 {
     using (var target = new TimeoutWatcher())
         using (var waitHandle = new ManualResetEventSlim())
         {
             target.Timeout += (sender, e) => waitHandle.Set();
             target.Start(_timeout);
             target.Stop();
             Assert.That(waitHandle.Wait(( int )(_timeout.TotalMilliseconds * 2)), Is.False);
             target.Reset();
             Assert.That(target.IsTimeout, Is.False);
         }
 }
        // called from SetCurrent
        internal RpcApplicationContext(TimeSpan?softTimeout, TimeSpan?hardTimeout)
        {
            this._softTimeout = softTimeout;
#if !SILVERLIGHT
            this._hardTimeout = hardTimeout;
#endif
            this._softTimeoutWatcher          = new TimeoutWatcher();
            this._softTimeoutWatcher.Timeout += (sender, e) => this.OnSoftTimeout();
#if !SILVERLIGHT
            this._hardTimeoutWatcher          = new TimeoutWatcher();
            this._hardTimeoutWatcher.Timeout += (sender, e) => this.OnHardTimeout();
#endif
            this._cancellationTokenSource = new CancellationTokenSource();
        }
 public void TestReset_CanStartAgain()
 {
     using (var target = new TimeoutWatcher())
         using (var waitHandle = new ManualResetEventSlim())
         {
             target.Timeout += (sender, e) => waitHandle.Set();
             for (int i = 0; i < 2; i++)
             {
                 Assert.That(target.IsTimeout, Is.False, "Attempt: {0}", i);
                 target.Start(_timeout);
                 Assert.That(waitHandle.Wait(TimeSpan.FromSeconds(1)), "Attempt: {0}", i);
                 Assert.That(target.IsTimeout, Is.True, "Attempt: {0}", i);
                 target.Reset();
                 waitHandle.Reset();
             }
         }
 }
示例#12
0
		public void TestStop_AfterTimeout_Harmless()
		{
			using ( var target = new TimeoutWatcher() )
			using ( var waitHandle = new ManualResetEventSlim() )
			{
				target.Timeout += ( sender, e ) => waitHandle.Set();
				target.Start( _timeout );
				Assert.That( waitHandle.Wait( TimeSpan.FromSeconds( 1 ) ) );
				target.Stop();
				Assert.That( target.IsTimeout, Is.True );
			}
		}
示例#13
0
		public void TestReset_CanStartAgain()
		{
			using ( var target = new TimeoutWatcher() )
			using ( var waitHandle = new ManualResetEventSlim() )
			{
				target.Timeout += ( sender, e ) => waitHandle.Set();
				for ( int i = 0; i < 2; i++ )
				{
					Assert.That( target.IsTimeout, Is.False, "Attempt: {0}", i );
					target.Start( _timeout );
					Assert.That( waitHandle.Wait( TimeSpan.FromSeconds( 1 ) ), "Attempt: {0}", i );
					Assert.That( target.IsTimeout, Is.True, "Attempt: {0}", i );
					target.Reset();
					waitHandle.Reset();
				}
			}
		}
示例#14
0
		// called from SetCurrent
		internal RpcApplicationContext( TimeSpan? softTimeout, TimeSpan? hardTimeout )
		{
			this._softTimeout = softTimeout;
#if !SILVERLIGHT
			this._hardTimeout = hardTimeout;
#endif
			this._softTimeoutWatcher = new TimeoutWatcher();
			this._softTimeoutWatcher.Timeout += ( sender, e ) => this.OnSoftTimeout();
#if !SILVERLIGHT
			this._hardTimeoutWatcher = new TimeoutWatcher();
			this._hardTimeoutWatcher.Timeout += ( sender, e ) => this.OnHardTimeout();
#endif
			this._cancellationTokenSource = new CancellationTokenSource();
		}