mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-09-10 17:25:51 +00:00
Harden PipeStream tests.
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user