From: Forest Date: Wed, 7 Jul 2021 05:16:38 +0000 (-0700) Subject: Fix a couple of flaky tests that didn't match usage expectations X-Git-Tag: 1.0.0~1^2~3 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=2930fea6e039d0227c4294edc09cecd7668f51c9;p=rhonda%2Fimpostor.hazel.git Fix a couple of flaky tests that didn't match usage expectations --- 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); } } }