Skip to content

Commit 7b58819

Browse files
authored
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
1 parent 70a0a08 commit 7b58819

13 files changed

+61
-79
lines changed

test/Renci.SshNet.Tests/Classes/ServiceFactoryTest_CreateShellStream_ChannelOpenThrowsException.cs

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Text;
43
using Microsoft.VisualStudio.TestTools.UnitTesting;
54
using Moq;
@@ -27,15 +26,13 @@ public class ServiceFactoryTest_CreateShellStream_ChannelOpenThrowsException
2726

2827
private void SetupData()
2928
{
30-
var random = new Random();
31-
32-
_terminalName = random.Next().ToString();
33-
_columns = (uint) random.Next();
34-
_rows = (uint) random.Next();
35-
_width = (uint) random.Next();
36-
_height = (uint) random.Next();
29+
_terminalName = "test";
30+
_columns = 80;
31+
_rows = 20;
32+
_width = 300;
33+
_height = 100;
3734
_terminalModeValues = new Dictionary<TerminalModes, uint>();
38-
_bufferSize = random.Next();
35+
_bufferSize = 512;
3936
_channelOpenException = new SshException();
4037

4138
_actualException = null;
@@ -117,4 +114,4 @@ public void DisposeOnChannelSessionShouldHaveBeenInvokedOnce()
117114
_channelSessionMock.Verify(p => p.Dispose(), Times.Once);
118115
}
119116
}
120-
}
117+
}

test/Renci.SshNet.Tests/Classes/ServiceFactoryTest_CreateShellStream_SendPseudoTerminalRequestReturnsFalse.cs

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Text;
43
using Microsoft.VisualStudio.TestTools.UnitTesting;
54
using Moq;
@@ -26,15 +25,13 @@ public class ServiceFactoryTest_CreateShellStream_SendPseudoTerminalRequestRetur
2625

2726
private void SetupData()
2827
{
29-
var random = new Random();
30-
31-
_terminalName = random.Next().ToString();
32-
_columns = (uint)random.Next();
33-
_rows = (uint)random.Next();
34-
_width = (uint)random.Next();
35-
_height = (uint)random.Next();
28+
_terminalName = "test";
29+
_columns = 80;
30+
_rows = 20;
31+
_width = 300;
32+
_height = 100;
3633
_terminalModeValues = new Dictionary<TerminalModes, uint>();
37-
_bufferSize = random.Next();
34+
_bufferSize = 512;
3835
_actualException = null;
3936
}
4037

@@ -117,4 +114,4 @@ public void DisposeOnChannelSessionShouldHaveBeenInvokedOnce()
117114
_channelSessionMock.Verify(p => p.Dispose(), Times.Once);
118115
}
119116
}
120-
}
117+
}

test/Renci.SshNet.Tests/Classes/ServiceFactoryTest_CreateShellStream_SendPseudoTerminalRequestThrowsException.cs

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Text;
43
using Microsoft.VisualStudio.TestTools.UnitTesting;
54
using Moq;
@@ -27,15 +26,13 @@ public class ServiceFactoryTest_CreateShellStream_SendPseudoTerminalRequestThrow
2726

2827
private void SetupData()
2928
{
30-
var random = new Random();
31-
32-
_terminalName = random.Next().ToString();
33-
_columns = (uint) random.Next();
34-
_rows = (uint) random.Next();
35-
_width = (uint) random.Next();
36-
_height = (uint) random.Next();
29+
_terminalName = "test";
30+
_columns = 80;
31+
_rows = 20;
32+
_width = 300;
33+
_height = 100;
3734
_terminalModeValues = new Dictionary<TerminalModes, uint>();
38-
_bufferSize = random.Next();
35+
_bufferSize = 512;
3936
_sendPseudoTerminalRequestException = new SshException();
4037

4138
_actualException = null;
@@ -119,4 +116,4 @@ public void DisposeOnChannelSessionShouldHaveBeenInvokedOnce()
119116
_channelSessionMock.Verify(p => p.Dispose(), Times.Once);
120117
}
121118
}
122-
}
119+
}

test/Renci.SshNet.Tests/Classes/ServiceFactoryTest_CreateShellStream_SendShellRequestReturnsFalse.cs

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Text;
43
using Microsoft.VisualStudio.TestTools.UnitTesting;
54
using Moq;
@@ -26,15 +25,13 @@ public class ServiceFactoryTest_CreateShellStream_SendShellRequestReturnsFalse
2625

2726
private void SetupData()
2827
{
29-
var random = new Random();
30-
31-
_terminalName = random.Next().ToString();
32-
_columns = (uint) random.Next();
33-
_rows = (uint) random.Next();
34-
_width = (uint) random.Next();
35-
_height = (uint) random.Next();
28+
_terminalName = "test";
29+
_columns = 80;
30+
_rows = 20;
31+
_width = 300;
32+
_height = 100;
3633
_terminalModeValues = new Dictionary<TerminalModes, uint>();
37-
_bufferSize = random.Next();
34+
_bufferSize = 512;
3835
_actualException = null;
3936
}
4037

@@ -120,4 +117,4 @@ public void DisposeOnChannelSessionShouldHaveBeenInvokedOnce()
120117
_channelSessionMock.Verify(p => p.Dispose(), Times.Once);
121118
}
122119
}
123-
}
120+
}

test/Renci.SshNet.Tests/Classes/ServiceFactoryTest_CreateShellStream_SendShellRequestThrowsException.cs

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Text;
43
using Microsoft.VisualStudio.TestTools.UnitTesting;
54
using Moq;
@@ -27,15 +26,13 @@ public class ServiceFactoryTest_CreateShellStream_SendShellRequestThrowsExceptio
2726

2827
private void SetupData()
2928
{
30-
var random = new Random();
31-
32-
_terminalName = random.Next().ToString();
33-
_columns = (uint) random.Next();
34-
_rows = (uint) random.Next();
35-
_width = (uint) random.Next();
36-
_height = (uint) random.Next();
29+
_terminalName = "test";
30+
_columns = 80;
31+
_rows = 20;
32+
_width = 300;
33+
_height = 100;
3734
_terminalModeValues = new Dictionary<TerminalModes, uint>();
38-
_bufferSize = random.Next();
35+
_bufferSize = 512;
3936
_sendShellRequestException = new SshException();
4037
_actualException = null;
4138
}
@@ -121,4 +118,4 @@ public void DisposeOnChannelSessionShouldHaveBeenInvokedOnce()
121118
_channelSessionMock.Verify(p => p.Dispose(), Times.Once);
122119
}
123120
}
124-
}
121+
}

test/Renci.SshNet.Tests/Classes/ServiceFactoryTest_CreateShellStream_Success.cs

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Text;
43
using Microsoft.VisualStudio.TestTools.UnitTesting;
54
using Moq;
@@ -26,15 +25,13 @@ public class ServiceFactoryTest_CreateShellStream_Success
2625

2726
private void SetupData()
2827
{
29-
var random = new Random();
30-
31-
_terminalName = random.Next().ToString();
32-
_columns = (uint) random.Next();
33-
_rows = (uint) random.Next();
34-
_width = (uint) random.Next();
35-
_height = (uint) random.Next();
28+
_terminalName = "test";
29+
_columns = 80;
30+
_rows = 20;
31+
_width = 300;
32+
_height = 100;
3633
_terminalModeValues = new Dictionary<TerminalModes, uint>();
37-
_bufferSize = random.Next();
34+
_bufferSize = 512;
3835
}
3936

4037
private void CreateMocks()
@@ -124,4 +121,4 @@ public void SendShellRequestShouldHaveBeenInvokedOnce()
124121
_channelSessionMock.Verify(p => p.SendShellRequest(), Times.Once);
125122
}
126123
}
127-
}
124+
}

test/Renci.SshNet.Tests/Classes/Sftp/SftpFileReaderTest_Read_ReahAheadExceptionInBeginRead.cs test/Renci.SshNet.Tests/Classes/Sftp/SftpFileReaderTest_Read_ReadAheadExceptionInBeginRead.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace Renci.SshNet.Tests.Classes.Sftp
1111
{
1212
[TestClass]
13-
public class SftpFileReaderTest_Read_ReahAheadExceptionInBeginRead : SftpFileReaderTestBase
13+
public class SftpFileReaderTest_Read_ReadAheadExceptionInBeginRead : SftpFileReaderTestBase
1414
{
1515
private const int ChunkLength = 32 * 1024;
1616

test/Renci.SshNet.Tests/Classes/Sftp/SftpFileReaderTest_Read_ReadAheadExceptionInWaitOnHandle_NoChunkAvailable.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected override void SetupData()
2929
var random = new Random();
3030

3131
_handle = CreateByteArray(random, 5);
32-
_fileSize = random.Next();
32+
_fileSize = 1234;
3333
_waitHandleArray = new WaitHandle[2];
3434
_operationTimeout = random.Next(10000, 20000);
3535
_closeAsyncResult = new SftpCloseAsyncResult(null, null);

test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionNotOpen.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected override void SetupData()
2828
_bufferSize = (uint) random.Next(1, 1000);
2929
_readBufferSize = (uint) random.Next(1, 1000);
3030
_writeBufferSize = (uint) random.Next(1, 1000);
31-
_length = random.Next();
31+
_length = 5555;
3232
}
3333

3434
protected override void SetupMocks()

test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessRead.cs test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FileAccessRead.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Renci.SshNet.Tests.Classes.Sftp
88
{
99
[TestClass]
10-
public class SftpFileStreamTest_SetLength_SessionOpen_FIleAccess : SftpFileStreamTestBase
10+
public class SftpFileStreamTest_SetLength_SessionOpen_FileAccessRead : SftpFileStreamTestBase
1111
{
1212
private SftpFileStream _target;
1313
private string _path;
@@ -28,7 +28,7 @@ protected override void SetupData()
2828
_bufferSize = (uint) random.Next(1, 1000);
2929
_readBufferSize = (uint) random.Next(1, 1000);
3030
_writeBufferSize = (uint) random.Next(1, 1000);
31-
_length = random.Next();
31+
_length = 6666;
3232
}
3333

3434
protected override void SetupMocks()

test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessReadWrite.cs test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FileAccessReadWrite.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Renci.SshNet.Tests.Classes.Sftp
1010
{
1111
[TestClass]
12-
public class SftpFileStreamTest_SetLength_SessionOpen_FIleAccessReadWrite
12+
public class SftpFileStreamTest_SetLength_SessionOpen_FileAccessReadWrite
1313
{
1414
private Mock<ISftpSession> _sftpSessionMock;
1515
private string _path;
@@ -46,7 +46,7 @@ protected void Arrange()
4646
_bufferSize = (uint) random.Next(1, 1000);
4747
_readBufferSize = (uint) random.Next(1, 1000);
4848
_writeBufferSize = (uint) random.Next(1, 1000);
49-
_length = random.Next();
49+
_length = 7777;
5050

5151
_fileAttributesLastAccessTime = DateTime.UtcNow.AddSeconds(random.Next());
5252
_fileAttributesLastWriteTime = DateTime.UtcNow.AddSeconds(random.Next());

test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessWrite.cs test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FileAccessWrite.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Renci.SshNet.Tests.Classes.Sftp
1010
{
1111
[TestClass]
12-
public class SftpFileStreamTest_SetLength_SessionOpen_FIleAccessWrite
12+
public class SftpFileStreamTest_SetLength_SessionOpen_FileAccessWrite
1313
{
1414
private Mock<ISftpSession> _sftpSessionMock;
1515
private string _path;
@@ -46,7 +46,7 @@ protected void Arrange()
4646
_bufferSize = (uint) random.Next(1, 1000);
4747
_readBufferSize = (uint) random.Next(1, 1000);
4848
_writeBufferSize = (uint) random.Next(1, 1000);
49-
_length = random.Next();
49+
_length = 8888;
5050

5151
_fileAttributesLastAccessTime = DateTime.UtcNow.AddSeconds(random.Next());
5252
_fileAttributesLastWriteTime = DateTime.UtcNow.AddSeconds(random.Next());

test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Write_SessionOpen_CountGreatherThanTwoTimesTheWriteBufferSize.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ public void LengthShouldFlushBufferAndReturnSizeOfFile()
121121
{
122122
var lengthFileAttributes = new SftpFileAttributes(DateTime.UtcNow,
123123
DateTime.UtcNow,
124-
_random.Next(),
125-
_random.Next(),
126-
_random.Next(),
127-
(uint) _random.Next(0, int.MaxValue),
124+
123,
125+
456,
126+
789,
127+
7,
128128
null);
129129
byte[] actualFlushedData = null;
130130

0 commit comments

Comments
 (0)