Skip to content

Commit 3a063b7

Browse files
authored
Add IsConnected to TcpBusClientSide (#111)
Adds an IsConnected property to the TcpBusClientSide so we don't need to put in a delay or otherwise guess when a connection has been established.
1 parent 2f5f1bf commit 3a063b7

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

src/ReactiveDomain.Transport.Tests/ReactiveDomain.Transport.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
</ItemGroup>
2020
<ItemGroup>
2121
<ProjectReference Include="..\ReactiveDomain.Messaging\ReactiveDomain.Messaging.csproj" />
22+
<ProjectReference Include="..\ReactiveDomain.Testing\ReactiveDomain.Testing.csproj" />
2223
<ProjectReference Include="..\ReactiveDomain.Transport\ReactiveDomain.Transport.csproj" />
2324
</ItemGroup>
2425
</Project>

src/ReactiveDomain.Transport.Tests/TcpBusClientSideTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Newtonsoft.Json;
99
using ReactiveDomain.Messaging;
1010
using ReactiveDomain.Messaging.Bus;
11+
using ReactiveDomain.Testing;
1112
using ReactiveDomain.Transport.Serialization;
1213
using Xunit;
1314

@@ -68,8 +69,8 @@ public TcpBusClientSideTests()
6869

6970
clientInbound.Start();
7071

71-
// wait for tcp connection to be established (maybe an api to detect this would be nice)
72-
Thread.Sleep(TimeSpan.FromMilliseconds(200));
72+
// wait for tcp connection to be established
73+
AssertEx.IsOrBecomesTrue(() => _tcpBusClientSide.IsConnected, 200);
7374
}
7475

7576
[Fact]

src/ReactiveDomain.Transport.Tests/TcpBusServerSideTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading.Tasks;
66
using ReactiveDomain.Messaging;
77
using ReactiveDomain.Messaging.Bus;
8+
using ReactiveDomain.Testing;
89
using Xunit;
910

1011
namespace ReactiveDomain.Transport.Tests
@@ -43,8 +44,8 @@ public void can_handle_split_frames()
4344
// client side
4445
var tcpBusClientSide = new TcpBusClientSide(_hostAddress, port);
4546

46-
// wait for tcp connection to be established (maybe an api to detect this would be nice)
47-
Thread.Sleep(TimeSpan.FromMilliseconds(200));
47+
// wait for tcp connection to be established
48+
AssertEx.IsOrBecomesTrue(() => tcpBusClientSide.IsConnected, 200);
4849

4950
// put message into client
5051
tcpBusClientSide.Handle(new WoftamEvent(prop1, prop2));
@@ -81,8 +82,8 @@ public void can_filter_out_message_types()
8182
// client side
8283
var tcpBusClientSide = new TcpBusClientSide(_hostAddress, port);
8384

84-
// wait for tcp connection to be established (maybe an api to detect this would be nice)
85-
Thread.Sleep(TimeSpan.FromMilliseconds(200));
85+
// wait for tcp connection to be established
86+
AssertEx.IsOrBecomesTrue(() => tcpBusClientSide.IsConnected, 200);
8687

8788
// put disallowed message into client
8889
tcpBusClientSide.Handle(new WoftamCommand("abc"));

src/ReactiveDomain.Transport/TcpBusClientSide.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace ReactiveDomain.Transport
1414
{
1515
public sealed class TcpBusClientSide : TcpBus
1616
{
17+
public bool IsConnected { get; private set; }
18+
1719
public TcpBusClientSide(
1820
EndPoint endpoint,
1921
IEnumerable<Type> inboundDiscardingMessageTypes,
@@ -66,11 +68,12 @@ private ITcpConnection CreateTcpConnection(EndPoint endPoint)
6668
conn =>
6769
{
6870
Log.Debug($"TcpBusClientSide.CreateTcpConnection({endPoint}) successfully constructed TcpConnection.");
69-
71+
IsConnected = true;
7072
ConfigureTcpListener(conn);
7173
},
7274
(conn, err) =>
7375
{
76+
IsConnected = false;
7477
HandleError(conn, err);
7578
},
7679
verbose: true);

0 commit comments

Comments
 (0)