Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add simple test for ReceiverDeadlockException

  • Loading branch information...
commit d7b9c0c19333d8af55a4c0f3cf86386532d9792c 1 parent 9d39498
@skarab skarab authored
View
28 IronSmarkets.Tests/ClientTests.cs
@@ -27,6 +27,7 @@
using IronSmarkets.Clients;
using IronSmarkets.Data;
+using IronSmarkets.Exceptions;
using IronSmarkets.Messages;
using IronSmarkets.Sessions;
using IronSmarkets.Sockets;
@@ -217,5 +218,32 @@ public void MultipleOrderCancelsAsynchronously()
client.Logout();
}
}
+
+ [Fact]
+ public void ReceiverDeadlockTest()
+ {
+ var socket = new MockSessionSocket();
+ socket.Expect(Payloads.Sequenced(Payloads.Login("mockuser", "mockpassword"), 1));
+ socket.Next(Payloads.Sequenced(Payloads.LoginResponse("00000000-0000-0000-0000-000000658a8", 2), 1));
+ socket.Expect(Payloads.Sequenced(Payloads.Ping(), 2));
+ socket.Next(Payloads.Sequenced(Payloads.Pong(), 2));
+ socket.Expect(Payloads.Sequenced(Payloads.Ping(), 3));
+
+ var session = new SeqSession(socket, SessionSettings);
+ IClientSettings mockSettings = new ClientSettings(SocketSettings, SessionSettings);
+ ManualResetEvent waiter = new ManualResetEvent(false);
+ using (var client = SmarketsClient.Create(mockSettings, session))
+ {
+ client.Login();
+ client.AddPayloadHandler(
+ (payload) => {
+ Assert.Throws<ReceiverDeadlockException>(() => client.Ping());
+ waiter.Set();
+ return true;
+ });
+ client.Ping();
+ waiter.WaitOne();
+ }
+ }
}
}
View
10 IronSmarkets/Messages/Payloads.cs
@@ -123,6 +123,16 @@ public static Payload Ping()
};
}
+ public static Payload Pong()
+ {
+ return new Payload {
+ Type = PayloadType.PAYLOADETO,
+ EtoPayload = new Eto.Payload {
+ Type = Eto.PayloadType.PAYLOADPONG
+ }
+ };
+ }
+
public static Payload MarketSubscribe(Uid market)
{
return new Payload {
Please sign in to comment.
Something went wrong with that request. Please try again.