TestSshCommand.NET40.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Diagnostics;
  3. using System.Text;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. using Microsoft.VisualStudio.TestTools.UnitTesting;
  7. using Renci.SshNet.Common;
  8. using Renci.SshNet.Tests.Properties;
  9. using System.IO;
  10. namespace Renci.SshNet.Tests.SshClientTests
  11. {
  12. public partial class TestSshCommand
  13. {
  14. //[TestMethod]
  15. public void Test_MultipleThread_10000_MultipleConnections()
  16. {
  17. try
  18. {
  19. System.Threading.Tasks.Parallel.For(0, 10000,
  20. () =>
  21. {
  22. var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD);
  23. client.Connect();
  24. return client;
  25. },
  26. (int counter, ParallelLoopState pls, SshClient client) =>
  27. {
  28. var result = ExecuteTestCommand(client);
  29. Debug.WriteLine(string.Format("TestMultipleThreadMultipleConnections #{0}", counter));
  30. Assert.IsTrue(result);
  31. return client;
  32. },
  33. (SshClient client) =>
  34. {
  35. client.Disconnect();
  36. client.Dispose();
  37. }
  38. );
  39. }
  40. catch (Exception exp)
  41. {
  42. Assert.Fail(exp.ToString());
  43. }
  44. }
  45. //[TestMethod]
  46. public void Test_MultipleThread_10000_MultipleSessions()
  47. {
  48. using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
  49. {
  50. client.Connect();
  51. System.Threading.Tasks.Parallel.For(0, 10000,
  52. (counter) =>
  53. {
  54. var result = ExecuteTestCommand(client);
  55. Debug.WriteLine(string.Format("TestMultipleThreadMultipleConnections #{0}", counter));
  56. Assert.IsTrue(result);
  57. }
  58. );
  59. client.Disconnect();
  60. }
  61. }
  62. }
  63. }