SshCommandTest.NET40.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Renci.SshNet.Tests.Properties;
  3. using System;
  4. using System.Diagnostics;
  5. using System.Threading.Tasks;
  6. namespace Renci.SshNet.Tests.Classes
  7. {
  8. public partial class SshCommandTest
  9. {
  10. public void Test_MultipleThread_Example_MultipleConnections()
  11. {
  12. var host = Resources.HOST;
  13. var username = Resources.USERNAME;
  14. var password = Resources.PASSWORD;
  15. try
  16. {
  17. #region Example SshCommand RunCommand Parallel
  18. System.Threading.Tasks.Parallel.For(0, 10000,
  19. () =>
  20. {
  21. var client = new SshClient(host, username, password);
  22. client.Connect();
  23. return client;
  24. },
  25. (int counter, ParallelLoopState pls, SshClient client) =>
  26. {
  27. var result = client.RunCommand("echo 123");
  28. Debug.WriteLine(string.Format("TestMultipleThreadMultipleConnections #{0}", counter));
  29. return client;
  30. },
  31. (SshClient client) =>
  32. {
  33. client.Disconnect();
  34. client.Dispose();
  35. }
  36. );
  37. #endregion
  38. }
  39. catch (Exception exp)
  40. {
  41. Assert.Fail(exp.ToString());
  42. }
  43. }
  44. //[TestMethod]
  45. public void Test_MultipleThread_10000_MultipleConnections()
  46. {
  47. try
  48. {
  49. System.Threading.Tasks.Parallel.For(0, 10000,
  50. () =>
  51. {
  52. var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD);
  53. client.Connect();
  54. return client;
  55. },
  56. (int counter, ParallelLoopState pls, SshClient client) =>
  57. {
  58. var result = ExecuteTestCommand(client);
  59. Debug.WriteLine(string.Format("TestMultipleThreadMultipleConnections #{0}", counter));
  60. Assert.IsTrue(result);
  61. return client;
  62. },
  63. (SshClient client) =>
  64. {
  65. client.Disconnect();
  66. client.Dispose();
  67. }
  68. );
  69. }
  70. catch (Exception exp)
  71. {
  72. Assert.Fail(exp.ToString());
  73. }
  74. }
  75. //[TestMethod]
  76. public void Test_MultipleThread_10000_MultipleSessions()
  77. {
  78. using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
  79. {
  80. client.Connect();
  81. System.Threading.Tasks.Parallel.For(0, 10000,
  82. (counter) =>
  83. {
  84. var result = ExecuteTestCommand(client);
  85. Debug.WriteLine(string.Format("TestMultipleThreadMultipleConnections #{0}", counter));
  86. Assert.IsTrue(result);
  87. }
  88. );
  89. client.Disconnect();
  90. }
  91. }
  92. }
  93. }