Skip to content

Significantly improved performance and fixed bug with ShellStream's Expect methods. #793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class ServiceFactoryTest_CreateShellStream_ChannelOpenThrowsException
private uint _height;
private IDictionary<TerminalModes, uint> _terminalModeValues;
private int _bufferSize;
private int _expectSize;
private SshException _channelOpenException;
private SshException _actualException;

Expand All @@ -30,12 +31,13 @@ private void SetupData()
var random = new Random();

_terminalName = random.Next().ToString();
_columns = (uint) random.Next();
_rows = (uint) random.Next();
_width = (uint) random.Next();
_height = (uint) random.Next();
_columns = (uint)random.Next();
_rows = (uint)random.Next();
_width = (uint)random.Next();
_height = (uint)random.Next();
_terminalModeValues = new Dictionary<TerminalModes, uint>();
_bufferSize = random.Next();
_expectSize = random.Next();
_channelOpenException = new SshException();

_actualException = null;
Expand Down Expand Up @@ -95,7 +97,8 @@ private void Act()
_width,
_height,
_terminalModeValues,
_bufferSize);
_bufferSize,
_expectSize);
Assert.Fail();
}
catch (SshException ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class ServiceFactoryTest_CreateShellStream_SendPseudoTerminalRequestRetur
private uint _height;
private IDictionary<TerminalModes, uint> _terminalModeValues;
private int _bufferSize;
private int _expectSize;
private SshException _actualException;

private void SetupData()
Expand All @@ -35,6 +36,7 @@ private void SetupData()
_height = (uint)random.Next();
_terminalModeValues = new Dictionary<TerminalModes, uint>();
_bufferSize = random.Next();
_expectSize = random.Next();
_actualException = null;
}

Expand Down Expand Up @@ -94,7 +96,8 @@ private void Act()
_width,
_height,
_terminalModeValues,
_bufferSize);
_bufferSize,
_expectSize);
Assert.Fail();
}
catch (SshException ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class ServiceFactoryTest_CreateShellStream_SendPseudoTerminalRequestThrow
private uint _height;
private IDictionary<TerminalModes, uint> _terminalModeValues;
private int _bufferSize;
private int _expectSize;
private SshException _sendPseudoTerminalRequestException;
private SshException _actualException;

Expand All @@ -30,12 +31,13 @@ private void SetupData()
var random = new Random();

_terminalName = random.Next().ToString();
_columns = (uint) random.Next();
_rows = (uint) random.Next();
_width = (uint) random.Next();
_height = (uint) random.Next();
_columns = (uint)random.Next();
_rows = (uint)random.Next();
_width = (uint)random.Next();
_height = (uint)random.Next();
_terminalModeValues = new Dictionary<TerminalModes, uint>();
_bufferSize = random.Next();
_expectSize = random.Next();
_sendPseudoTerminalRequestException = new SshException();

_actualException = null;
Expand Down Expand Up @@ -97,7 +99,8 @@ private void Act()
_width,
_height,
_terminalModeValues,
_bufferSize);
_bufferSize,
_expectSize);
Assert.Fail();
}
catch (SshException ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@ public class ServiceFactoryTest_CreateShellStream_SendShellRequestReturnsFalse
private uint _height;
private IDictionary<TerminalModes, uint> _terminalModeValues;
private int _bufferSize;
private int _expectSize;
private SshException _actualException;

private void SetupData()
{
var random = new Random();

_terminalName = random.Next().ToString();
_columns = (uint) random.Next();
_rows = (uint) random.Next();
_width = (uint) random.Next();
_height = (uint) random.Next();
_columns = (uint)random.Next();
_rows = (uint)random.Next();
_width = (uint)random.Next();
_height = (uint)random.Next();
_terminalModeValues = new Dictionary<TerminalModes, uint>();
_bufferSize = random.Next();
_expectSize = random.Next();
_actualException = null;
}

Expand Down Expand Up @@ -97,7 +99,8 @@ private void Act()
_width,
_height,
_terminalModeValues,
_bufferSize);
_bufferSize,
_expectSize);
Assert.Fail();
}
catch (SshException ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class ServiceFactoryTest_CreateShellStream_SendShellRequestThrowsExceptio
private uint _height;
private IDictionary<TerminalModes, uint> _terminalModeValues;
private int _bufferSize;
private int _expectSize;
private SshException _sendShellRequestException;
private SshException _actualException;

Expand All @@ -30,12 +31,13 @@ private void SetupData()
var random = new Random();

_terminalName = random.Next().ToString();
_columns = (uint) random.Next();
_rows = (uint) random.Next();
_width = (uint) random.Next();
_height = (uint) random.Next();
_columns = (uint)random.Next();
_rows = (uint)random.Next();
_width = (uint)random.Next();
_height = (uint)random.Next();
_terminalModeValues = new Dictionary<TerminalModes, uint>();
_bufferSize = random.Next();
_expectSize = random.Next();
_sendShellRequestException = new SshException();
_actualException = null;
}
Expand Down Expand Up @@ -99,7 +101,8 @@ private void Act()
_width,
_height,
_terminalModeValues,
_bufferSize);
_bufferSize,
_expectSize);
Assert.Fail();
}
catch (SshException ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@ public class ServiceFactoryTest_CreateShellStream_Success
private uint _height;
private IDictionary<TerminalModes, uint> _terminalModeValues;
private int _bufferSize;
private int _expectSize;
private ShellStream _shellStream;

private void SetupData()
{
var random = new Random();

_terminalName = random.Next().ToString();
_columns = (uint) random.Next();
_rows = (uint) random.Next();
_width = (uint) random.Next();
_height = (uint) random.Next();
_columns = (uint)random.Next();
_rows = (uint)random.Next();
_width = (uint)random.Next();
_height = (uint)random.Next();
_terminalModeValues = new Dictionary<TerminalModes, uint>();
_bufferSize = random.Next();
_expectSize = random.Next();
}

private void CreateMocks()
Expand Down Expand Up @@ -97,7 +99,8 @@ private void Act()
_width,
_height,
_terminalModeValues,
_bufferSize);
_bufferSize,
_expectSize);
}

[TestMethod]
Expand Down
27 changes: 15 additions & 12 deletions src/Renci.SshNet.Tests/Classes/ShellStreamTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class ShellStreamTest : TestBase
private uint _heightPixels;
private Dictionary<TerminalModes, uint> _terminalModes;
private int _bufferSize;
private int _expectSize;
private Mock<IChannelSession> _channelSessionMock;

protected override void OnInit()
Expand All @@ -35,12 +36,13 @@ protected override void OnInit()

var random = new Random();
_terminalName = random.Next().ToString(CultureInfo.InvariantCulture);
_widthColumns = (uint) random.Next();
_heightRows = (uint) random.Next();
_widthColumns = (uint)random.Next();
_heightRows = (uint)random.Next();
_widthPixels = (uint)random.Next();
_heightPixels = (uint)random.Next();
_terminalModes = new Dictionary<TerminalModes, uint>();
_bufferSize = random.Next(100, 500);
_expectSize = random.Next(100, 500);

_encoding = Encoding.UTF8;
_sessionMock = new Mock<ISession>(MockBehavior.Strict);
Expand All @@ -61,15 +63,15 @@ public void ReadLine_MultiByteCharacters()
var shellStream = CreateShellStream();

var channelDataPublishThread = new Thread(() =>
{
_channelSessionMock.Raise(p => p.DataReceived += null,
new ChannelDataEventArgs(5, _encoding.GetBytes(data1)));
Thread.Sleep(50);
_channelSessionMock.Raise(p => p.DataReceived += null,
new ChannelDataEventArgs(5, _encoding.GetBytes(data2 + "\r\n")));
_channelSessionMock.Raise(p => p.DataReceived += null,
new ChannelDataEventArgs(5, _encoding.GetBytes(data3 + "\r\n")));
});
{
_channelSessionMock.Raise(p => p.DataReceived += null,
new ChannelDataEventArgs(5, _encoding.GetBytes(data1)));
Thread.Sleep(50);
_channelSessionMock.Raise(p => p.DataReceived += null,
new ChannelDataEventArgs(5, _encoding.GetBytes(data2 + "\r\n")));
_channelSessionMock.Raise(p => p.DataReceived += null,
new ChannelDataEventArgs(5, _encoding.GetBytes(data3 + "\r\n")));
});
channelDataPublishThread.Start();

Assert.AreEqual(data1 + data2, shellStream.ReadLine());
Expand Down Expand Up @@ -120,7 +122,8 @@ private ShellStream CreateShellStream()
_widthPixels,
_heightPixels,
_terminalModes,
_bufferSize);
_bufferSize,
_expectSize);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class ShellStreamTest_Write_WriteBufferEmptyAndWriteLessBytesThanBufferSi
private Dictionary<TerminalModes, uint> _terminalModes;
private ShellStream _shellStream;
private int _bufferSize;
private int _expectSize;

private byte[] _data;
private int _offset;
Expand All @@ -41,12 +42,13 @@ private void SetupData()
var random = new Random();

_terminalName = random.Next().ToString();
_widthColumns = (uint) random.Next();
_heightRows = (uint) random.Next();
_widthPixels = (uint) random.Next();
_heightPixels = (uint) random.Next();
_widthColumns = (uint)random.Next();
_heightRows = (uint)random.Next();
_widthPixels = (uint)random.Next();
_heightPixels = (uint)random.Next();
_terminalModes = new Dictionary<TerminalModes, uint>();
_bufferSize = random.Next(100, 1000);
_expectSize = random.Next(100, 1000);

_data = CryptoAbstraction.GenerateRandom(_bufferSize - 10);
_offset = random.Next(1, 5);
Expand Down Expand Up @@ -101,7 +103,8 @@ private void Arrange()
_widthPixels,
_heightPixels,
_terminalModes,
_bufferSize);
_bufferSize,
_expectSize);
}

private void Act()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ShellStreamTest_Write_WriteBufferEmptyAndWriteMoreBytesThanBufferSi
private Dictionary<TerminalModes, uint> _terminalModes;
private ShellStream _shellStream;
private int _bufferSize;
private int _expectSize;

private byte[] _data;
private int _offset;
Expand All @@ -50,6 +51,7 @@ private void SetupData()
_heightPixels = (uint)random.Next();
_terminalModes = new Dictionary<TerminalModes, uint>();
_bufferSize = random.Next(100, 1000);
_expectSize = random.Next(100, 1000);

_data = CryptoAbstraction.GenerateRandom(_bufferSize * 2 + 10);
_offset = 0;
Expand Down Expand Up @@ -111,7 +113,8 @@ private void Arrange()
_widthPixels,
_heightPixels,
_terminalModes,
_bufferSize);
_bufferSize,
_expectSize);
}

private void Act()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class ShellStreamTest_Write_WriteBufferEmptyAndWriteNumberOfBytesEqualToB
private Dictionary<TerminalModes, uint> _terminalModes;
private ShellStream _shellStream;
private int _bufferSize;
private int _expectSize;

private byte[] _data;
private int _offset;
Expand All @@ -47,6 +48,7 @@ private void SetupData()
_heightPixels = (uint)random.Next();
_terminalModes = new Dictionary<TerminalModes, uint>();
_bufferSize = random.Next(100, 1000);
_expectSize = random.Next(100, 1000);

_data = CryptoAbstraction.GenerateRandom(_bufferSize);
_offset = 0;
Expand Down Expand Up @@ -101,7 +103,8 @@ private void Arrange()
_widthPixels,
_heightPixels,
_terminalModes,
_bufferSize);
_bufferSize,
_expectSize);
}

private void Act()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class ShellStreamTest_Write_WriteBufferEmptyAndWriteZeroBytes
private Dictionary<TerminalModes, uint> _terminalModes;
private ShellStream _shellStream;
private int _bufferSize;
private int _expectSize;

private byte[] _data;
private int _offset;
Expand All @@ -47,6 +48,7 @@ private void SetupData()
_heightPixels = (uint)random.Next();
_terminalModes = new Dictionary<TerminalModes, uint>();
_bufferSize = random.Next(100, 1000);
_expectSize = random.Next(100, 1000);

_data = new byte[0];
_offset = 0;
Expand Down Expand Up @@ -101,7 +103,8 @@ private void Arrange()
_widthPixels,
_heightPixels,
_terminalModes,
_bufferSize);
_bufferSize,
_expectSize);
}

private void Act()
Expand Down
Loading