コード例 #1
0
        public void ConnectionTimeoutTestWithThread()
        {
            int    timeoutSec          = 5;
            string connStrNotAvailable = $"Server=tcp:fakeServer,1433;uid=fakeuser;pwd=fakepwd;Connection Timeout={timeoutSec}";

            List <ConnectionWorker> list = new List <ConnectionWorker>();

            for (int i = 0; i < 10; ++i)
            {
                list.Add(new ConnectionWorker(connStrNotAvailable));
            }

            ConnectionWorker.Start();
            ConnectionWorker.Stop();

            double theMax = 0;

            foreach (ConnectionWorker w in list)
            {
                if (theMax < w.MaxTimeElapsed)
                {
                    theMax = w.MaxTimeElapsed;
                }
            }

            int threshold = (timeoutSec + 1) * 1000;

            Console.WriteLine($"ConnectionTimeoutTestWithThread: Elapsed Time {theMax} and threshold {threshold}");
        }
コード例 #2
0
        public static void ConnectionTimeoutTestWithThread()
        {
            const int timeoutSec   = 5;
            const int numOfTry     = 2;
            const int numOfThreads = 5;

            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(DataTestUtility.TCPConnectionString);

            builder.DataSource     = "invalidhost";
            builder.ConnectTimeout = timeoutSec;
            string connStrNotAvailable = builder.ConnectionString;

            for (int i = 0; i < numOfThreads; ++i)
            {
                new ConnectionWorker(connStrNotAvailable, numOfTry);
            }

            ConnectionWorker.Start();
            ConnectionWorker.Stop();

            double timeTotal   = 0;
            double timeElapsed = 0;

            foreach (ConnectionWorker w in ConnectionWorker.WorkerList)
            {
                timeTotal += w.TimeElapsed;
            }
            timeElapsed = timeTotal / Convert.ToDouble(ConnectionWorker.WorkerList.Count);

            int threshold = timeoutSec * numOfTry * 2 * 1000;

            Assert.True(timeElapsed < threshold);
        }
コード例 #3
0
//	private bool IsPortUse(int port)
//	{
//		IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
//		IPEndPoint[] arr = properties.GetActiveUdpListeners();
//		foreach (var item in arr) {
//			Debug.Log("udpPort:" + item.Port);
//			if(item.Port == port)return true;
//		}
//		return false;
//	}

    public void StopBroadcast()
    {
        if (!stop)
        {
            try
            {
                broadcastWorker.Stop();
                broadcastWorker.Dispose();
                broadcastWorker = null;
                stop            = true;
            }catch (Exception e)
            {
                GUITextDebug.debug(e.Message + "\n" + e.StackTrace);
            }
        }
    }