From 39fab42f5c278828bb6cf97f27fa207475adab58 Mon Sep 17 00:00:00 2001 From: Eric Fortin Date: Tue, 18 Feb 2025 09:06:59 -0500 Subject: [PATCH 1/2] SOFT-1999 Null exception in NEventSocket.Util.StringExtensions.ToOriginateString --- NEventSocket/Util/StringExtensions.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/NEventSocket/Util/StringExtensions.cs b/NEventSocket/Util/StringExtensions.cs index 0918030..926e5a8 100644 --- a/NEventSocket/Util/StringExtensions.cs +++ b/NEventSocket/Util/StringExtensions.cs @@ -221,9 +221,11 @@ public static string ToOriginateString(this IDictionary dictiona foreach (var kvp in dictionary) { - sb.AppendFormat("{0}='{1}',", kvp.Key, kvp.Value.Replace(",", @"\,")); + if (kvp.Value != null) + { + sb.AppendFormat("{0}='{1}',", kvp.Key, kvp.Value.Replace(",", @"\,")); + } } - return StringBuilderPool.ReturnAndFree(sb); } } From f4251be2547a670488ec8a2d385608507d9cc68b Mon Sep 17 00:00:00 2001 From: Eric Fortin Date: Wed, 23 Jul 2025 13:59:22 -0400 Subject: [PATCH 2/2] SOFT-1999 Test correction --- .../Sockets/InboundSocketTests.cs | 8 +-- .../Sockets/OutboundSocketTests.cs | 69 ++++--------------- 2 files changed, 16 insertions(+), 61 deletions(-) diff --git a/NEventSocket.Tests/Sockets/InboundSocketTests.cs b/NEventSocket.Tests/Sockets/InboundSocketTests.cs index 9285dc9..d185ec3 100644 --- a/NEventSocket.Tests/Sockets/InboundSocketTests.cs +++ b/NEventSocket.Tests/Sockets/InboundSocketTests.cs @@ -117,7 +117,7 @@ public void when_no_AuthRequest_received_it_should_throw_TimeoutException_wrappe } } - [Test, CancelAfter(5000), Ignore("Removing timeouts")] + [Test, CancelAfter(5000)] public void when_no_response_to_auth_received_it_should_throw_TimeoutException_wrapped_in_InboundSocketConnectionFailedException() { using (var listener = new FakeFreeSwitchListener(0)) @@ -172,7 +172,7 @@ public async Task can_send_api() } } - [Test, CancelAfter(5000), Ignore("Removing timeouts")] + [Test, CancelAfter(5000)] public async Task when_no_api_response_received_it_should_throw_a_TimeOutException() { using (var listener = new FakeFreeSwitchListener(0)) @@ -305,7 +305,7 @@ public async Task can_send_multiple_commands() } } - [Test, CancelAfter(5000), Ignore("Removing timeouts")] + [Test, CancelAfter(5000)] public async Task when_no_command_reply_received_it_should_throw_a_TimeOutException() { using (var listener = new FakeFreeSwitchListener(0)) @@ -344,7 +344,7 @@ public async Task when_no_command_reply_received_it_should_throw_a_TimeOutExcept } } - [Test, CancelAfter(TimeOut.TestTimeOutMs), Ignore("Removing timeouts")] + [Test, CancelAfter(TimeOut.TestTimeOutMs)] public async Task when_the_inbound_socket_is_disposed_it_should_complete_the_observables() { using (var listener = new FakeFreeSwitchListener(0)) diff --git a/NEventSocket.Tests/Sockets/OutboundSocketTests.cs b/NEventSocket.Tests/Sockets/OutboundSocketTests.cs index 27117c2..02f3684 100644 --- a/NEventSocket.Tests/Sockets/OutboundSocketTests.cs +++ b/NEventSocket.Tests/Sockets/OutboundSocketTests.cs @@ -32,7 +32,7 @@ public void SetUp() } - [Test, CancelAfter(TimeOut.TestTimeOutMs), Ignore("Removing timeouts")] + [Test, CancelAfter(TimeOut.TestTimeOutMs)] public async Task Disposing_the_listener_completes_the_message_observables() { using (var listener = new OutboundListener(0)) @@ -61,8 +61,8 @@ public async Task Disposing_the_listener_completes_the_message_observables() .Subscribe(async _ => await freeSwitch.SendChannelDataEvent()); await Wait.Until(() => channelDataReceived); - listener.Dispose(); // will dispose the socket - + // Remove redundant disposal - using statement handles this + await Wait.Until(() => messagesObservableCompleted); await Wait.Until(() => eventsObservableCompleted); @@ -96,16 +96,16 @@ public async Task When_FreeSwitch_disconnects_it_completes_the_message_observabl using (var client = new FakeFreeSwitchSocket(listener.Port)) { await Wait.Until(() => connected); - client.Dispose(); + // Removed explicit client.Dispose() - it will be disposed automatically by the using statement + } - await Wait.Until(() => messagesObservableCompleted); - await Wait.Until(() => eventsObservableCompleted); + await Wait.Until(() => messagesObservableCompleted); + await Wait.Until(() => eventsObservableCompleted); - Assert.That(connected, Is.True, "Expect a connection to have been made."); - Assert.That(disposed, Is.True, "Expect the socket to have been disposed."); - Assert.That(messagesObservableCompleted, Is.True, "Expect the BasicMessage observable to be completed"); - Assert.That(eventsObservableCompleted, Is.True, "Expect the EventMessage observable to be completed"); - } + Assert.That(connected, Is.True, "Expect a connection to have been made."); + Assert.That(disposed, Is.True, "Expect the socket to have been disposed."); + Assert.That(messagesObservableCompleted, Is.True, "Expect the BasicMessage observable to be completed"); + Assert.That(eventsObservableCompleted, Is.True, "Expect the EventMessage observable to be completed"); } } @@ -172,7 +172,7 @@ public async Task Calling_Exit_on_a_disconnected_OutboundSocket_should_close_gra } } - [Test, CancelAfter(TimeOut.TestTimeOutMs), Ignore("Low priority right now")] + [Test, CancelAfter(TimeOut.TestTimeOutMs)] public async Task Calling_Connect_on_a_OutboundSocket_that_was_disconnected_should_throw_OperationCanceledException() { using (var listener = new OutboundListener(0)) @@ -217,51 +217,6 @@ public async Task Channel_listener_should_handle_where_FS_disconnects_before_cha } } - [Test, CancelAfter(TimeOut.TestTimeOutMs), Ignore("not working in some test runners")] - public async Task Channel_connect_errors_should_not_cause_subsequent_connections_to_fail() - { - using (var listener = new OutboundListener(0)) - { - listener.Start(); - bool channelCallbackCalled = false; - bool firstConnectionReceived = false; - bool secondConnectionReceived = false; - - listener.Channels.Subscribe(channel => { channelCallbackCalled = true; }); - - using (var freeSwitch = new FakeFreeSwitchSocket(listener.Port)) - { - freeSwitch.MessagesReceived.FirstAsync(m => m.StartsWith("connect")).Subscribe(_ => - { - freeSwitch.Dispose(); - firstConnectionReceived = true; - }); - - await Wait.Until(() => firstConnectionReceived); - Assert.That(channelCallbackCalled, Is.False); - } - - using (var freeSwitch = new FakeFreeSwitchSocket(listener.Port)) - { - freeSwitch.MessagesReceived.FirstAsync(m => m.StartsWith("connect")).Subscribe(async _ => - { - await freeSwitch.SendChannelDataEvent(); - secondConnectionReceived = true; - }); - - freeSwitch.MessagesReceived.FirstAsync(m => m.StartsWith("linger") || m.StartsWith("event") || m.StartsWith("filter")) - .Subscribe(async _ => - { - await freeSwitch.SendCommandReplyOk("sending OK for linger, event and filter commands"); - }); - - - await Wait.Until(() => secondConnectionReceived); - Assert.That(channelCallbackCalled, Is.True); - } - } - } - [Test, CancelAfter(TimeOut.TestTimeOutMs)] public async Task can_send_api() {