void CheckPollInterval(TcpClientTestClass client, TcpServer server, int interval) { client.PollResult = true; client.PollInterval = interval; client.PollColledCount = 0; var waitStart = DateTime.Now; while (client.PollColledCount == 0) { var dta = DateTime.Now - waitStart; if (dta.TotalSeconds > 5) { Assert.Fail("Wait Timeout"); } } var now = DateTime.Now; client.PollColledCount = 0; client.PollCalledDateTime = DateTime.MinValue; Assert.AreEqual(interval, client.PollInterval); Assert.AreEqual(DateTime.MinValue, client.PollCalledDateTime); Assert.AreEqual(0, client.PollColledCount); Thread.Sleep((int)(1.5 * client.PollInterval)); Assert.AreEqual(1, client.PollColledCount); Assert.AreNotEqual(DateTime.MinValue, client.PollCalledDateTime); var delta = client.PollCalledDateTime - now; var minDelta = interval - interval * 100; var maxDelta = interval + interval * 100; Assert.IsTrue(minDelta <= delta.TotalMilliseconds); Assert.IsTrue(maxDelta >= delta.TotalMilliseconds); }
public void PollTest() { var server = new TcpServer(); var epList = new List <TcpServerLocalEndpoint>(); var ipEp1 = (new TcpServerLocalEndpoint(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 0192), 1)); epList.Add(ipEp1); server.DataReceivedEvent += Server_DataReceivedEvent; server.Start(epList); var client = new TcpClientTestClass(); client.ErrorEvent += Client_ErrorEvent; client.DisconnectedEvent += Client_DisconnectedEvent; client.ConnectedEvent += Client_ConnectedEvent; client.Start(ipEp1.EndPoint); Thread.Sleep(200); CheckPollInterval(client, server, 100); CheckPollInterval(client, server, 500); CheckPollInterval(client, server, 1000); CheckPollInterval(client, server, 2000); CheckPollFailCount(client, server, 1); CheckPollFailCount(client, server, 3); CheckPollFailCount(client, server, 5); CheckPollFailCount(client, server, 10); client.Dispose(); server.Dispose(); }
public void PollTest() { var serverName = "TestServer"; using (X509Certificate serverCert = MakeCert(serverName)) { var server = new TcpServer(); var epList = new List <TcpServerLocalEndpoint>(); var ipEp1 = (new TcpServerLocalEndpoint(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 0192), 1)); epList.Add(ipEp1); server.DataReceivedEvent += Server_DataReceivedEvent; server.Start(epList, serverCert, false, SslProtocols.None, false, EncryptionPolicy.RequireEncryption); X509Certificate clientCert = MakeCert(serverName); var client = new TcpClientTestClass(); client.ErrorEvent += Client_ErrorEvent; client.DisconnectedEvent += Client_DisconnectedEvent; client.ConnectedEvent += Client_ConnectedEvent; client.Start(ipEp1.EndPoint, serverName, clientCert, SslProtocols.None, false, EncryptionPolicy.RequireEncryption); Thread.Sleep(200); CheckPollInterval(client, server, 100); CheckPollInterval(client, server, 500); CheckPollInterval(client, server, 1000); CheckPollInterval(client, server, 2000); CheckPollFailCount(client, server, 1); CheckPollFailCount(client, server, 3); CheckPollFailCount(client, server, 5); CheckPollFailCount(client, server, 10); client.Dispose(); server.Dispose(); clientCert.Dispose(); } }
void CheckPollFailCount(TcpClientTestClass client, TcpServer server, int count) { client.PollResult = true; client.PollInterval = 100; client.PollFailLimit = count; client.PollColledCount = 0; var waitStart = DateTime.Now; while (client.PollColledCount == 0) { var delta = DateTime.Now - waitStart; if (delta.TotalSeconds > 5) { Assert.Fail("Wait Timeout"); } } client.PollColledCount = 0; Assert.AreEqual(0, client.PollColledCount); client.PollResult = false; ClientDisconnectedEventCalled = false; waitStart = DateTime.Now; while (!ClientDisconnectedEventCalled) { var delta = DateTime.Now - waitStart; if (delta.TotalSeconds > 5) { Assert.Fail("Wait Timeout"); } } Assert.AreEqual(count, client.PollFailLimit); Assert.AreEqual(count, client.PollColledCount); }