From 2930fea6e039d0227c4294edc09cecd7668f51c9 Mon Sep 17 00:00:00 2001 From: Forest Date: Tue, 6 Jul 2021 22:16:38 -0700 Subject: [PATCH] Fix a couple of flaky tests that didn't match usage expectations --- Hazel.UnitTests/ThreadLimitedUdpConnectionTests.cs | 9 ++++++--- Hazel.UnitTests/UnityUdpConnectionTests.cs | 7 ++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Hazel.UnitTests/ThreadLimitedUdpConnectionTests.cs b/Hazel.UnitTests/ThreadLimitedUdpConnectionTests.cs index a65355c..4be1628 100644 --- a/Hazel.UnitTests/ThreadLimitedUdpConnectionTests.cs +++ b/Hazel.UnitTests/ThreadLimitedUdpConnectionTests.cs @@ -5,6 +5,8 @@ using System.Threading; using Hazel.Udp; using Hazel.Udp.FewerThreads; using System.Net.Sockets; +using System.Linq; +using System.Collections; namespace Hazel.UnitTests { @@ -461,12 +463,13 @@ namespace Hazel.UnitTests using (ThreadLimitedUdpConnectionListener listener = this.CreateListener(2, new IPEndPoint(IPAddress.Any, 4296), new TestLogger())) using (UdpConnection connection = this.CreateConnection(new IPEndPoint(IPAddress.Loopback, 4296), new TestLogger())) { - MessageReader received = null; + string received = null; ManualResetEvent mutex = new ManualResetEvent(false); connection.Disconnected += delegate (object sender, DisconnectedEventArgs args) { - received = args.Message; + // We don't own the message, we have to read the string now + received = args.Message.ReadString(); mutex.Set(); }; @@ -484,7 +487,7 @@ namespace Hazel.UnitTests mutex.WaitOne(); Assert.IsNotNull(received); - Assert.AreEqual("Goodbye", received.ReadString()); + Assert.AreEqual("Goodbye", received); } } } diff --git a/Hazel.UnitTests/UnityUdpConnectionTests.cs b/Hazel.UnitTests/UnityUdpConnectionTests.cs index 0597df4..5151ae2 100644 --- a/Hazel.UnitTests/UnityUdpConnectionTests.cs +++ b/Hazel.UnitTests/UnityUdpConnectionTests.cs @@ -449,12 +449,13 @@ namespace Hazel.UnitTests using (UdpConnectionListener listener = new UdpConnectionListener(new IPEndPoint(IPAddress.Any, 4296))) using (UdpConnection connection = new UnityUdpClientConnection(new IPEndPoint(IPAddress.Loopback, 4296))) { - MessageReader received = null; + string received = null; ManualResetEvent mutex = new ManualResetEvent(false); connection.Disconnected += delegate (object sender, DisconnectedEventArgs args) { - received = args.Message; + // We don't own the message, we have to read the string now + received = args.Message.ReadString(); mutex.Set(); }; @@ -478,7 +479,7 @@ namespace Hazel.UnitTests mutex.WaitOne(); Assert.IsNotNull(received); - Assert.AreEqual("Goodbye", received.ReadString()); + Assert.AreEqual("Goodbye", received); } } } -- 2.39.5