Browse Source

Harden PipeStream tests.

drieseng 9 years ago
parent
commit
d7b1106151

+ 5 - 3
src/Renci.SshNet.Tests/Common/PipeStream_Close_BlockingRead.cs → src/Renci.SshNet.Tests/Classes/Common/PipeStream_Close_BlockingRead.cs

@@ -1,9 +1,8 @@
 using System;
-using System.Threading;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Renci.SshNet.Common;
 
-namespace Renci.SshNet.Tests.Common
+namespace Renci.SshNet.Tests.Classes.Common
 {
     [TestClass]
     public class PipeStream_Close_BlockingRead
@@ -34,12 +33,15 @@ namespace Renci.SshNet.Tests.Common
         protected void Act()
         {
             _pipeStream.Close();
+
+            // give async read time to complete
+            _asyncReadResult.AsyncWaitHandle.WaitOne(100);
         }
 
         [TestMethod]
         public void BlockingReadShouldHaveBeenInterrupted()
         {
-            Assert.IsTrue(_asyncReadResult.AsyncWaitHandle.WaitOne(200));
+            Assert.IsTrue(_asyncReadResult.IsCompleted);
         }
 
         [TestMethod]

+ 5 - 4
src/Renci.SshNet.Tests/Common/PipeStream_Close_BlockingWrite.cs → src/Renci.SshNet.Tests/Classes/Common/PipeStream_Close_BlockingWrite.cs

@@ -2,7 +2,7 @@
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Renci.SshNet.Common;
 
-namespace Renci.SshNet.Tests.Common
+namespace Renci.SshNet.Tests.Classes.Common
 {
     [TestClass]
     public class PipeStream_Close_BlockingWrite
@@ -44,19 +44,20 @@ namespace Renci.SshNet.Tests.Common
         protected void Act()
         {
             _pipeStream.Close();
+
+            // give async write time to complete
+            _asyncWriteResult.AsyncWaitHandle.WaitOne(100);
         }
 
         [TestMethod]
         public void BlockingWriteShouldHaveBeenInterrupted()
         {
-            Assert.IsTrue(_asyncWriteResult.AsyncWaitHandle.WaitOne(200));
+            Assert.IsTrue(_asyncWriteResult.IsCompleted);
         }
 
         [TestMethod]
         public void WriteShouldHaveThrownObjectDisposedException()
         {
-            _asyncWriteResult.AsyncWaitHandle.WaitOne(200);
-
             Assert.IsNotNull(_writeException);
             Assert.AreEqual(typeof (ObjectDisposedException), _writeException.GetType());
         }

+ 4 - 1
src/Renci.SshNet.Tests/Common/PipeStream_Flush_BytesRemainingAfterRead.cs → src/Renci.SshNet.Tests/Classes/Common/PipeStream_Flush_BytesRemainingAfterRead.cs

@@ -3,7 +3,7 @@ using System.Threading;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Renci.SshNet.Common;
 
-namespace Renci.SshNet.Tests.Common
+namespace Renci.SshNet.Tests.Classes.Common
 {
     [TestClass]
     public class PipeStream_Flush_BytesRemainingAfterRead
@@ -37,6 +37,9 @@ namespace Renci.SshNet.Tests.Common
         protected void Act()
         {
             _pipeStream.Flush();
+
+            // give async read time to complete
+            _asyncReadResult.AsyncWaitHandle.WaitOne(100);
         }
 
         [TestMethod]

+ 4 - 1
src/Renci.SshNet.Tests/Common/PipeStream_Flush_NoBytesRemainingAfterRead.cs → src/Renci.SshNet.Tests/Classes/Common/PipeStream_Flush_NoBytesRemainingAfterRead.cs

@@ -2,7 +2,7 @@
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Renci.SshNet.Common;
 
-namespace Renci.SshNet.Tests.Common
+namespace Renci.SshNet.Tests.Classes.Common
 {
     [TestClass]
     public class PipeStream_Flush_NoBytesRemainingAfterRead
@@ -32,6 +32,9 @@ namespace Renci.SshNet.Tests.Common
         protected void Act()
         {
             _pipeStream.Flush();
+
+            // give async read time to complete
+            _asyncReadResult.AsyncWaitHandle.WaitOne(100);
         }
 
         [TestMethod]

+ 4 - 4
src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj

@@ -445,10 +445,10 @@
     <Compile Include="Common\AsyncSocketListener.cs" />
     <Compile Include="Common\HttpProxyStub.cs" />
     <Compile Include="Common\HttpRequest.cs" />
-    <Compile Include="Common\PipeStream_Close_BlockingRead.cs" />
-    <Compile Include="Common\PipeStream_Close_BlockingWrite.cs" />
-    <Compile Include="Common\PipeStream_Flush_BytesRemainingAfterRead.cs" />
-    <Compile Include="Common\PipeStream_Flush_NoBytesRemainingAfterRead.cs" />
+    <Compile Include="Classes\Common\PipeStream_Close_BlockingRead.cs" />
+    <Compile Include="Classes\Common\PipeStream_Close_BlockingWrite.cs" />
+    <Compile Include="Classes\Common\PipeStream_Flush_BytesRemainingAfterRead.cs" />
+    <Compile Include="Classes\Common\PipeStream_Flush_NoBytesRemainingAfterRead.cs" />
     <Compile Include="Common\TestBase.cs" />
     <Compile Include="Classes\Compression\CompressorTest.cs" />
     <Compile Include="Classes\Common\DerDataTest.cs" />