| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 | using Microsoft.VisualStudio.TestTools.UnitTesting;using Renci.SshNet.Tests.Properties;using System;using System.Diagnostics;using System.Threading.Tasks;namespace Renci.SshNet.Tests.Classes{    public partial class SshCommandTest    {        public void Test_MultipleThread_Example_MultipleConnections()        {            var host = Resources.HOST;            var username = Resources.USERNAME;            var password = Resources.PASSWORD;            try            {                #region Example SshCommand RunCommand Parallel                System.Threading.Tasks.Parallel.For(0, 10000,                    () =>                    {                        var client = new SshClient(host, username, password);                        client.Connect();                        return client;                    },                    (int counter, ParallelLoopState pls, SshClient client) =>                    {                        var result = client.RunCommand("echo 123");                        Debug.WriteLine(string.Format("TestMultipleThreadMultipleConnections #{0}", counter));                        return client;                    },                    (SshClient client) =>                    {                        client.Disconnect();                        client.Dispose();                    }                );                #endregion            }            catch (Exception exp)            {                Assert.Fail(exp.ToString());            }        }        //[TestMethod]        public void Test_MultipleThread_10000_MultipleConnections()        {            try            {                System.Threading.Tasks.Parallel.For(0, 10000,                    () =>                    {                        var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD);                        client.Connect();                        return client;                    },                    (int counter, ParallelLoopState pls, SshClient client) =>                    {                        var result = ExecuteTestCommand(client);                        Debug.WriteLine(string.Format("TestMultipleThreadMultipleConnections #{0}", counter));                        Assert.IsTrue(result);                        return client;                    },                    (SshClient client) =>                    {                        client.Disconnect();                        client.Dispose();                    }                );            }            catch (Exception exp)            {                Assert.Fail(exp.ToString());            }        }        //[TestMethod]        public void Test_MultipleThread_10000_MultipleSessions()        {            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))            {                client.Connect();                System.Threading.Tasks.Parallel.For(0, 10000,                    (counter) =>                    {                        var result = ExecuteTestCommand(client);                        Debug.WriteLine(string.Format("TestMultipleThreadMultipleConnections #{0}", counter));                        Assert.IsTrue(result);                    }                );                client.Disconnect();            }        }    }}
 |