2
0
Эх сурвалжийг харах

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
Rob Hague 1 жил өмнө
parent
commit
7b58819537
13 өөрчлөгдсөн 61 нэмэгдсэн , 79 устгасан
  1. 8 11
      test/Renci.SshNet.Tests/Classes/ServiceFactoryTest_CreateShellStream_ChannelOpenThrowsException.cs
  2. 8 11
      test/Renci.SshNet.Tests/Classes/ServiceFactoryTest_CreateShellStream_SendPseudoTerminalRequestReturnsFalse.cs
  3. 8 11
      test/Renci.SshNet.Tests/Classes/ServiceFactoryTest_CreateShellStream_SendPseudoTerminalRequestThrowsException.cs
  4. 8 11
      test/Renci.SshNet.Tests/Classes/ServiceFactoryTest_CreateShellStream_SendShellRequestReturnsFalse.cs
  5. 8 11
      test/Renci.SshNet.Tests/Classes/ServiceFactoryTest_CreateShellStream_SendShellRequestThrowsException.cs
  6. 8 11
      test/Renci.SshNet.Tests/Classes/ServiceFactoryTest_CreateShellStream_Success.cs
  7. 1 1
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileReaderTest_Read_ReadAheadExceptionInBeginRead.cs
  8. 1 1
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileReaderTest_Read_ReadAheadExceptionInWaitOnHandle_NoChunkAvailable.cs
  9. 1 1
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionNotOpen.cs
  10. 2 2
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FileAccessRead.cs
  11. 2 2
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FileAccessReadWrite.cs
  12. 2 2
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FileAccessWrite.cs
  13. 4 4
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Write_SessionOpen_CountGreatherThanTwoTimesTheWriteBufferSize.cs

+ 8 - 11
test/Renci.SshNet.Tests/Classes/ServiceFactoryTest_CreateShellStream_ChannelOpenThrowsException.cs

@@ -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);
         }
     }
-}
+}

+ 8 - 11
test/Renci.SshNet.Tests/Classes/ServiceFactoryTest_CreateShellStream_SendPseudoTerminalRequestReturnsFalse.cs

@@ -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);
         }
     }
-}
+}

+ 8 - 11
test/Renci.SshNet.Tests/Classes/ServiceFactoryTest_CreateShellStream_SendPseudoTerminalRequestThrowsException.cs

@@ -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);
         }
     }
-}
+}

+ 8 - 11
test/Renci.SshNet.Tests/Classes/ServiceFactoryTest_CreateShellStream_SendShellRequestReturnsFalse.cs

@@ -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);
         }
     }
-}
+}

+ 8 - 11
test/Renci.SshNet.Tests/Classes/ServiceFactoryTest_CreateShellStream_SendShellRequestThrowsException.cs

@@ -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);
         }
     }
-}
+}

+ 8 - 11
test/Renci.SshNet.Tests/Classes/ServiceFactoryTest_CreateShellStream_Success.cs

@@ -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);
         }
     }
-}
+}

+ 1 - 1
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileReaderTest_Read_ReahAheadExceptionInBeginRead.cs → test/Renci.SshNet.Tests/Classes/Sftp/SftpFileReaderTest_Read_ReadAheadExceptionInBeginRead.cs

@@ -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;
 

+ 1 - 1
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileReaderTest_Read_ReadAheadExceptionInWaitOnHandle_NoChunkAvailable.cs

@@ -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);

+ 1 - 1
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionNotOpen.cs

@@ -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()

+ 2 - 2
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessRead.cs → test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FileAccessRead.cs

@@ -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()

+ 2 - 2
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessReadWrite.cs → test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FileAccessReadWrite.cs

@@ -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());

+ 2 - 2
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessWrite.cs → test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FileAccessWrite.cs

@@ -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());

+ 4 - 4
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Write_SessionOpen_CountGreatherThanTwoTimesTheWriteBufferSize.cs

@@ -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;