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

* debugging CI

* apt-get

* print memory

* x

* x

* Remove some unbounded random.Next() calls

Some of which are causing giant array allocations unnecessarily. Should stabilise CI.

* cleanup
This commit is contained in:
Rob Hague
2024-04-06 21:37:59 +02:00
committed by GitHub
parent 70a0a08dae
commit 7b58819537
13 changed files with 61 additions and 79 deletions
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
@@ -27,15 +26,13 @@ namespace Renci.SshNet.Tests.Classes
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;
@@ -117,4 +114,4 @@ namespace Renci.SshNet.Tests.Classes
_channelSessionMock.Verify(p => p.Dispose(), Times.Once);
}
}
}
}
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
@@ -26,15 +25,13 @@ namespace Renci.SshNet.Tests.Classes
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;
}
@@ -117,4 +114,4 @@ namespace Renci.SshNet.Tests.Classes
_channelSessionMock.Verify(p => p.Dispose(), Times.Once);
}
}
}
}
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
@@ -27,15 +26,13 @@ namespace Renci.SshNet.Tests.Classes
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;
@@ -119,4 +116,4 @@ namespace Renci.SshNet.Tests.Classes
_channelSessionMock.Verify(p => p.Dispose(), Times.Once);
}
}
}
}
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
@@ -26,15 +25,13 @@ namespace Renci.SshNet.Tests.Classes
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;
}
@@ -120,4 +117,4 @@ namespace Renci.SshNet.Tests.Classes
_channelSessionMock.Verify(p => p.Dispose(), Times.Once);
}
}
}
}
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
@@ -27,15 +26,13 @@ namespace Renci.SshNet.Tests.Classes
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;
}
@@ -121,4 +118,4 @@ namespace Renci.SshNet.Tests.Classes
_channelSessionMock.Verify(p => p.Dispose(), Times.Once);
}
}
}
}
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
@@ -26,15 +25,13 @@ namespace Renci.SshNet.Tests.Classes
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()
@@ -124,4 +121,4 @@ namespace Renci.SshNet.Tests.Classes
_channelSessionMock.Verify(p => p.SendShellRequest(), Times.Once);
}
}
}
}
@@ -10,7 +10,7 @@ using BufferedRead = Renci.SshNet.Sftp.SftpFileReader.BufferedRead;
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;
@@ -29,7 +29,7 @@ namespace Renci.SshNet.Tests.Classes.Sftp
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);
@@ -28,7 +28,7 @@ namespace Renci.SshNet.Tests.Classes.Sftp
_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()
@@ -7,7 +7,7 @@ using Renci.SshNet.Sftp;
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;
@@ -28,7 +28,7 @@ namespace Renci.SshNet.Tests.Classes.Sftp
_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()
@@ -9,7 +9,7 @@ using Renci.SshNet.Sftp;
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;
@@ -46,7 +46,7 @@ namespace Renci.SshNet.Tests.Classes.Sftp
_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());
@@ -9,7 +9,7 @@ using Renci.SshNet.Sftp;
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;
@@ -46,7 +46,7 @@ namespace Renci.SshNet.Tests.Classes.Sftp
_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());
@@ -121,10 +121,10 @@ namespace Renci.SshNet.Tests.Classes.Sftp
{
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;