Skip to content

Remove enormous array allocations in tests causing instability in CI #1367

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

Merged
merged 8 commits into from
Apr 6, 2024
Merged
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
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
Expand Down Expand Up @@ -27,15 +26,13 @@ public class ServiceFactoryTest_CreateShellStream_ChannelOpenThrowsException

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();
_terminalName = "test";
_columns = 80;
_rows = 20;
_width = 300;
_height = 100;
_terminalModeValues = new Dictionary<TerminalModes, uint>();
_bufferSize = random.Next();
_bufferSize = 512;
_channelOpenException = new SshException();

_actualException = null;
Expand Down Expand Up @@ -117,4 +114,4 @@ public void DisposeOnChannelSessionShouldHaveBeenInvokedOnce()
_channelSessionMock.Verify(p => p.Dispose(), Times.Once);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
Expand All @@ -26,15 +25,13 @@ public class ServiceFactoryTest_CreateShellStream_SendPseudoTerminalRequestRetur

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();
_terminalName = "test";
_columns = 80;
_rows = 20;
_width = 300;
_height = 100;
_terminalModeValues = new Dictionary<TerminalModes, uint>();
_bufferSize = random.Next();
_bufferSize = 512;
_actualException = null;
}

Expand Down Expand Up @@ -117,4 +114,4 @@ public void DisposeOnChannelSessionShouldHaveBeenInvokedOnce()
_channelSessionMock.Verify(p => p.Dispose(), Times.Once);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
Expand Down Expand Up @@ -27,15 +26,13 @@ public class ServiceFactoryTest_CreateShellStream_SendPseudoTerminalRequestThrow

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();
_terminalName = "test";
_columns = 80;
_rows = 20;
_width = 300;
_height = 100;
_terminalModeValues = new Dictionary<TerminalModes, uint>();
_bufferSize = random.Next();
_bufferSize = 512;
_sendPseudoTerminalRequestException = new SshException();

_actualException = null;
Expand Down Expand Up @@ -119,4 +116,4 @@ public void DisposeOnChannelSessionShouldHaveBeenInvokedOnce()
_channelSessionMock.Verify(p => p.Dispose(), Times.Once);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
Expand All @@ -26,15 +25,13 @@ public class ServiceFactoryTest_CreateShellStream_SendShellRequestReturnsFalse

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();
_terminalName = "test";
_columns = 80;
_rows = 20;
_width = 300;
_height = 100;
_terminalModeValues = new Dictionary<TerminalModes, uint>();
_bufferSize = random.Next();
_bufferSize = 512;
_actualException = null;
}

Expand Down Expand Up @@ -120,4 +117,4 @@ public void DisposeOnChannelSessionShouldHaveBeenInvokedOnce()
_channelSessionMock.Verify(p => p.Dispose(), Times.Once);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
Expand Down Expand Up @@ -27,15 +26,13 @@ public class ServiceFactoryTest_CreateShellStream_SendShellRequestThrowsExceptio

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();
_terminalName = "test";
_columns = 80;
_rows = 20;
_width = 300;
_height = 100;
_terminalModeValues = new Dictionary<TerminalModes, uint>();
_bufferSize = random.Next();
_bufferSize = 512;
_sendShellRequestException = new SshException();
_actualException = null;
}
Expand Down Expand Up @@ -121,4 +118,4 @@ public void DisposeOnChannelSessionShouldHaveBeenInvokedOnce()
_channelSessionMock.Verify(p => p.Dispose(), Times.Once);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
Expand All @@ -26,15 +25,13 @@ public class ServiceFactoryTest_CreateShellStream_Success

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();
_terminalName = "test";
_columns = 80;
_rows = 20;
_width = 300;
_height = 100;
_terminalModeValues = new Dictionary<TerminalModes, uint>();
_bufferSize = random.Next();
_bufferSize = 512;
}

private void CreateMocks()
Expand Down Expand Up @@ -124,4 +121,4 @@ public void SendShellRequestShouldHaveBeenInvokedOnce()
_channelSessionMock.Verify(p => p.SendShellRequest(), Times.Once);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Renci.SshNet.Tests.Classes.Sftp
{
[TestClass]
public class SftpFileReaderTest_Read_ReahAheadExceptionInBeginRead : SftpFileReaderTestBase
public class SftpFileReaderTest_Read_ReadAheadExceptionInBeginRead : SftpFileReaderTestBase
{
private const int ChunkLength = 32 * 1024;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected override void SetupData()
var random = new Random();

_handle = CreateByteArray(random, 5);
_fileSize = random.Next();
_fileSize = 1234;
_waitHandleArray = new WaitHandle[2];
_operationTimeout = random.Next(10000, 20000);
_closeAsyncResult = new SftpCloseAsyncResult(null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected override void SetupData()
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
_length = random.Next();
_length = 5555;
}

protected override void SetupMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Renci.SshNet.Tests.Classes.Sftp
{
[TestClass]
public class SftpFileStreamTest_SetLength_SessionOpen_FIleAccess : SftpFileStreamTestBase
public class SftpFileStreamTest_SetLength_SessionOpen_FileAccessRead : SftpFileStreamTestBase
{
private SftpFileStream _target;
private string _path;
Expand All @@ -28,7 +28,7 @@ protected override void SetupData()
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
_length = random.Next();
_length = 6666;
}

protected override void SetupMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Renci.SshNet.Tests.Classes.Sftp
{
[TestClass]
public class SftpFileStreamTest_SetLength_SessionOpen_FIleAccessReadWrite
public class SftpFileStreamTest_SetLength_SessionOpen_FileAccessReadWrite
{
private Mock<ISftpSession> _sftpSessionMock;
private string _path;
Expand Down Expand Up @@ -46,7 +46,7 @@ protected void Arrange()
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
_length = random.Next();
_length = 7777;

_fileAttributesLastAccessTime = DateTime.UtcNow.AddSeconds(random.Next());
_fileAttributesLastWriteTime = DateTime.UtcNow.AddSeconds(random.Next());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Renci.SshNet.Tests.Classes.Sftp
{
[TestClass]
public class SftpFileStreamTest_SetLength_SessionOpen_FIleAccessWrite
public class SftpFileStreamTest_SetLength_SessionOpen_FileAccessWrite
{
private Mock<ISftpSession> _sftpSessionMock;
private string _path;
Expand Down Expand Up @@ -46,7 +46,7 @@ protected void Arrange()
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
_length = random.Next();
_length = 8888;

_fileAttributesLastAccessTime = DateTime.UtcNow.AddSeconds(random.Next());
_fileAttributesLastWriteTime = DateTime.UtcNow.AddSeconds(random.Next());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ public void LengthShouldFlushBufferAndReturnSizeOfFile()
{
var lengthFileAttributes = new SftpFileAttributes(DateTime.UtcNow,
DateTime.UtcNow,
_random.Next(),
_random.Next(),
_random.Next(),
(uint) _random.Next(0, int.MaxValue),
123,
456,
789,
7,
null);
byte[] actualFlushedData = null;

Expand Down