Harden PipeStream tests.

This commit is contained in:
drieseng
2016-06-25 12:58:08 +02:00
parent f3f0239162
commit b86eba0d7c
2 changed files with 25 additions and 19 deletions
@@ -25,6 +25,7 @@ namespace Renci.SshNet.Tests.Common
Action readAction = () => _bytesRead = _pipeStream.Read(new byte[4], 0, 4);
_asyncReadResult = readAction.BeginInvoke(null, null);
// ensure we've started reading
_asyncReadResult.AsyncWaitHandle.WaitOne(50);
Act();
@@ -36,9 +37,9 @@ namespace Renci.SshNet.Tests.Common
}
[TestMethod]
public void AsyncReadShouldHaveFinished()
public void BlockingReadShouldHaveBeenInterrupted()
{
Assert.IsTrue(_asyncReadResult.IsCompleted);
Assert.IsTrue(_asyncReadResult.AsyncWaitHandle.WaitOne(200));
}
[TestMethod]
@@ -17,22 +17,25 @@ namespace Renci.SshNet.Tests.Common
_pipeStream = new PipeStream {MaxBufferLength = 3};
Action writeAction = () =>
{
_pipeStream.WriteByte(10);
_pipeStream.WriteByte(13);
_pipeStream.WriteByte(25);
{
_pipeStream.WriteByte(10);
_pipeStream.WriteByte(13);
_pipeStream.WriteByte(25);
try
{
_pipeStream.WriteByte(35);
}
catch (Exception ex)
{
_writeException = ex;
throw;
}
};
// attempting to write more bytes than the max. buffer length should block
// until bytes are read or the stream is closed
try
{
_pipeStream.WriteByte(35);
}
catch (Exception ex)
{
_writeException = ex;
throw;
}
};
_asyncWriteResult = writeAction.BeginInvoke(null, null);
// ensure we've started writing
_asyncWriteResult.AsyncWaitHandle.WaitOne(50);
Act();
@@ -44,14 +47,16 @@ namespace Renci.SshNet.Tests.Common
}
[TestMethod]
public void AsyncWriteShouldHaveFinished()
public void BlockingWriteShouldHaveBeenInterrupted()
{
Assert.IsTrue(_asyncWriteResult.IsCompleted);
Assert.IsTrue(_asyncWriteResult.AsyncWaitHandle.WaitOne(200));
}
[TestMethod]
public void WriteThatExceedsMaxBufferLengthShouldHaveThrownObjectDisposedException()
public void WriteShouldHaveThrownObjectDisposedException()
{
_asyncWriteResult.AsyncWaitHandle.WaitOne(200);
Assert.IsNotNull(_writeException);
Assert.AreEqual(typeof (ObjectDisposedException), _writeException.GetType());
}