]> git.deb.at Git - rhonda/impostor.hazel.git/commitdiff
Fix some flaky tests, clean up some style
authorForest <chocozilla@gmail.com>
Thu, 20 Jun 2019 21:30:09 +0000 (14:30 -0700)
committerForest <chocozilla@gmail.com>
Thu, 20 Jun 2019 21:30:09 +0000 (14:30 -0700)
Hazel.UnitTests/UdpConnectionTests.cs
Hazel/ConnectionListener.cs
Hazel/Udp/UdpClientConnection.cs

index efd485752d21d3b096d4260bc7f3683f111d69d2..aa154ced700afe13080eb8362bc07a2752423773 100644 (file)
@@ -31,8 +31,9 @@ namespace Hazel.UnitTests
                 listener.Start();
                 connection.Connect();
 
+                Thread.Sleep(100); // Gotta wait for the server to set up the events.
                 listener.Dispose();
-                Thread.Sleep(10);
+                Thread.Sleep(100);
 
                 Assert.IsTrue(serverConnected);
                 Assert.IsTrue(clientDisconnected);
@@ -62,6 +63,8 @@ namespace Hazel.UnitTests
 
                 listener.Start();
                 connection.Connect();
+
+                Thread.Sleep(100); // Gotta wait for the server to set up the events.
                 connection.Dispose();
 
                 Thread.Sleep(100);
@@ -314,7 +317,7 @@ namespace Hazel.UnitTests
                 connection.Connect();
                 connection.KeepAliveInterval = 100;
 
-                System.Threading.Thread.Sleep(1050);    //Enough time for ~10 keep alive packets
+                Thread.Sleep(1050);    //Enough time for ~10 keep alive packets
 
                 Assert.AreEqual(ConnectionState.Connected, connection.State);
                 Assert.IsTrue(
index 20064e35620becd55bbd9eb13e096c9357cdff87..9d9c66413d3dfbbf2de6deaff6da8bbf0903f9f0 100644 (file)
@@ -1,9 +1,4 @@
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net;
-using System.Text;
-
 
 namespace Hazel
 {
@@ -76,7 +71,7 @@ namespace Hazel
         /// </remarks>
         protected void InvokeNewConnection(MessageReader msg, Connection connection)
         {
-            //Make a copy to avoid race condition between null check and invocation
+            // Make a copy to avoid race condition between null check and invocation
             Action<NewConnectionEventArgs> handler = NewConnection;
             if (handler != null)
             {
index 7d155f2aed92b2ce4c4be18b35968eba810cfdff..fd4145b5899087dfea09429aa5143fadfed88f6d 100644 (file)
@@ -139,7 +139,6 @@ namespace Hazel.Udp
         {
             this.State = ConnectionState.Connecting;
 
-            //Begin listening
             try
             {
                 if (IPMode == IPMode.IPv4)
@@ -149,7 +148,7 @@ namespace Hazel.Udp
             }
             catch (SocketException e)
             {
-                State = ConnectionState.NotConnected;
+                this.State = ConnectionState.NotConnected;
                 throw new HazelException("A socket exception occured while binding to the port.", e);
             }
 
@@ -159,9 +158,9 @@ namespace Hazel.Udp
             }
             catch (ObjectDisposedException)
             {
-                //If the socket's been disposed then we can just end there but make sure we're in NotConnected state.
-                //If we end up here I'm really lost...
-                State = ConnectionState.NotConnected;
+                // If the socket's been disposed then we can just end there but make sure we're in NotConnected state.
+                // If we end up here I'm really lost...
+                this.State = ConnectionState.NotConnected;
                 return;
             }
             catch (SocketException e)
@@ -170,9 +169,9 @@ namespace Hazel.Udp
                 throw new HazelException("A Socket exception occured while initiating a receive operation.", e);
             }
 
-            //Write bytes to the server to tell it hi (and to punch a hole in our NAT, if present)
-            //When acknowledged set the state to connected
-            SendHello(bytes, () => { State = ConnectionState.Connected; });
+            // Write bytes to the server to tell it hi (and to punch a hole in our NAT, if present)
+            // When acknowledged set the state to connected
+            SendHello(bytes, () => { this.State = ConnectionState.Connected; });
         }
 
         /// <summary>