From bbf3af41d1a3dcaf0dc35267ace8709d2a914998 Mon Sep 17 00:00:00 2001 From: Forest Date: Thu, 20 Jun 2019 14:30:09 -0700 Subject: [PATCH] Fix some flaky tests, clean up some style --- Hazel.UnitTests/UdpConnectionTests.cs | 7 +++++-- Hazel/ConnectionListener.cs | 7 +------ Hazel/Udp/UdpClientConnection.cs | 15 +++++++-------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Hazel.UnitTests/UdpConnectionTests.cs b/Hazel.UnitTests/UdpConnectionTests.cs index efd4857..aa154ce 100644 --- a/Hazel.UnitTests/UdpConnectionTests.cs +++ b/Hazel.UnitTests/UdpConnectionTests.cs @@ -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( diff --git a/Hazel/ConnectionListener.cs b/Hazel/ConnectionListener.cs index 20064e3..9d9c664 100644 --- a/Hazel/ConnectionListener.cs +++ b/Hazel/ConnectionListener.cs @@ -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 /// 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 handler = NewConnection; if (handler != null) { diff --git a/Hazel/Udp/UdpClientConnection.cs b/Hazel/Udp/UdpClientConnection.cs index 7d155f2..fd4145b 100644 --- a/Hazel/Udp/UdpClientConnection.cs +++ b/Hazel/Udp/UdpClientConnection.cs @@ -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; }); } /// -- 2.39.5