Skip to content

Commit

Permalink
Reverse logic for testing TooLow and TooHigh when
Browse files Browse the repository at this point in the history
recieving a SequenceReset with GapFill=Y
Reversing logic allows the GapFill to be applied during message resend.
Discussion:
connamara#309 (comment)
  • Loading branch information
Oliver Clancy committed Jul 14, 2023
1 parent 16846e5 commit c8d46d8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
16 changes: 8 additions & 8 deletions QuickFIXn/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ public void Next()

if (!IsSessionTime)
{
if(IsInitiator)
if (IsInitiator)
Reset("Out of SessionTime (Session.Next())");
else
Reset("Out of SessionTime (Session.Next())", "Message received outside of session time");
Expand Down Expand Up @@ -830,7 +830,7 @@ protected void NextResendRequest(Message resendReq)
{

initializeResendFields(msg);
if(!ResendApproved(msg, SessionID))
if (!ResendApproved(msg, SessionID))
{
continue;
}
Expand Down Expand Up @@ -926,7 +926,7 @@ protected void NextSequenceReset(Message sequenceReset)
if (sequenceReset.IsSetField(Fields.Tags.GapFillFlag))
isGapFill = sequenceReset.GetBoolean(Fields.Tags.GapFillFlag);

if (!Verify(sequenceReset, isGapFill, isGapFill))
if (!Verify(sequenceReset, !isGapFill, !isGapFill))
return;

if (sequenceReset.IsSetField(Fields.Tags.NewSeqNo))
Expand Down Expand Up @@ -1058,7 +1058,7 @@ public void Reset(string loggedReason)
/// <param name="logoutMessage">message to put in the Logout message's Text field (ignored if null/empty string)</param>
public void Reset(string loggedReason, string logoutMessage)
{
if(this.IsLoggedOn)
if (this.IsLoggedOn)
GenerateLogout(logoutMessage);
Disconnect("Resetting...");
state_.Reset(loggedReason);
Expand Down Expand Up @@ -1150,7 +1150,7 @@ protected void DoPossDup(Message msg)
{
// If config RequiresOrigSendingTime=N, then tolerate SequenceReset messages that lack OrigSendingTime (issue #102).
// (This field doesn't really make sense in this message, so some parties omit it, even though spec requires it.)
string msgType = msg.Header.GetString(Fields.Tags.MsgType);
string msgType = msg.Header.GetString(Fields.Tags.MsgType);
if (msgType == Fields.MsgType.SEQUENCE_RESET && RequiresOrigSendingTime == false)
return;

Expand Down Expand Up @@ -1388,7 +1388,7 @@ internal bool GenerateReject(MessageBuilder msgBuilder, FixValues.SessionRejectR
{
return GenerateReject(msgBuilder.RejectableMessage(), reason, 0);
}

internal bool GenerateReject(MessageBuilder msgBuilder, FixValues.SessionRejectReason reason, int field)
{
return GenerateReject(msgBuilder.RejectableMessage(), reason, field);
Expand Down Expand Up @@ -1533,7 +1533,7 @@ protected void InsertSendingTime(FieldMap header)
else
fix42OrAbove = this.SessionID.BeginString.CompareTo(FixValues.BeginString.FIX42) >= 0;

header.SetField(new Fields.SendingTime(System.DateTime.UtcNow, fix42OrAbove ? TimeStampPrecision : TimeStampPrecision.Second ) );
header.SetField(new Fields.SendingTime(System.DateTime.UtcNow, fix42OrAbove ? TimeStampPrecision : TimeStampPrecision.Second));
}

protected void Persist(Message message, string messageString)
Expand Down Expand Up @@ -1595,7 +1595,7 @@ protected void InsertOrigSendingTime(FieldMap header, System.DateTime sendingTim
else
fix42OrAbove = this.SessionID.BeginString.CompareTo(FixValues.BeginString.FIX42) >= 0;

header.SetField(new OrigSendingTime(sendingTime, fix42OrAbove ? TimeStampPrecision : TimeStampPrecision.Second ) );
header.SetField(new OrigSendingTime(sendingTime, fix42OrAbove ? TimeStampPrecision : TimeStampPrecision.Second));
}
protected void NextQueued()
{
Expand Down
46 changes: 23 additions & 23 deletions UnitTests/SessionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MockResponder : QuickFix.IResponder

#region Responder Members
QuickFix.DefaultMessageFactory messageFactory = new QuickFix.DefaultMessageFactory();

public Dictionary<string, Queue<QuickFix.Message>> msgLookup = new Dictionary<string, Queue<QuickFix.Message>>();
public Queue<QuickFix.Message> dups = new Queue<QuickFix.Message>();

Expand All @@ -38,7 +38,7 @@ public bool Send(string msgStr)
if (message.Header.IsSetField(possDup))
message.Header.GetField(possDup);

if (possDup.getValue() && msgType.getValue()!= QuickFix.Fields.MsgType.SEQUENCE_RESET)
if (possDup.getValue() && msgType.getValue() != QuickFix.Fields.MsgType.SEQUENCE_RESET)
{
dups.Enqueue(message);
}
Expand Down Expand Up @@ -97,7 +97,7 @@ public void ToApp(QuickFix.Message message, QuickFix.SessionID sessionId)
{
if (doNotSendException != null)
throw doNotSendException;

}

public void FromApp(QuickFix.Message message, QuickFix.SessionID sessionID)
Expand Down Expand Up @@ -198,7 +198,7 @@ public void Setup()

// acceptor
session = new QuickFix.Session(false, application, new QuickFix.MemoryStoreFactory(), sessionID,
new QuickFix.DataDictionaryProvider(),new QuickFix.SessionSchedule(config), 0, logFactory, new QuickFix.DefaultMessageFactory(), "blah");
new QuickFix.DataDictionaryProvider(), new QuickFix.SessionSchedule(config), 0, logFactory, new QuickFix.DefaultMessageFactory(), "blah");
session.SetResponder(responder);
session.CheckLatency = false;

Expand Down Expand Up @@ -254,15 +254,15 @@ public bool RESENT()

public bool SENT_REJECT()
{
return responder.msgLookup.ContainsKey(QuickFix.Fields.MsgType.REJECT) &&
responder.msgLookup[QuickFix.Fields.MsgType.REJECT].Count>0;
return responder.msgLookup.ContainsKey(QuickFix.Fields.MsgType.REJECT) &&
responder.msgLookup[QuickFix.Fields.MsgType.REJECT].Count > 0;
}

public bool SENT_HEART_BEAT()
{
public bool SENT_HEART_BEAT()
{
return responder.msgLookup.ContainsKey(QuickFix.Fields.MsgType.HEARTBEAT) &&
responder.msgLookup[QuickFix.Fields.MsgType.HEARTBEAT].Count > 0;
}
}

public bool SENT_BUSINESS_REJECT()
{
Expand Down Expand Up @@ -317,7 +317,7 @@ public bool SENT_REJECT(int reason, int refTag)

QuickFix.Fields.SessionRejectReason reasonField = new QuickFix.Fields.SessionRejectReason();
msg.GetField(reasonField);
if(reasonField.getValue() != reason)
if (reasonField.getValue() != reason)
return false;

if (!msg.IsSetField(QuickFix.Fields.Tags.RefTagID))
Expand Down Expand Up @@ -373,7 +373,7 @@ private void SendTheMessage(QuickFix.Message msg)

[Test]
public void ConditionalTagMissingReject()
{
{
application.fromAppException = new QuickFix.FieldNotFoundException(61);

Logon();
Expand All @@ -388,10 +388,10 @@ public void ConditionalTagMissingReject()
public void IncorrectTagValueReject()
{
application.fromAppException = new QuickFix.IncorrectTagValue(54);

Logon();
SendNOSMessage();
Assert.That(SENT_REJECT(QuickFix.Fields.SessionRejectReason.VALUE_IS_INCORRECT,54));
Assert.That(SENT_REJECT(QuickFix.Fields.SessionRejectReason.VALUE_IS_INCORRECT, 54));

}

Expand All @@ -408,7 +408,7 @@ public void UnsupportedMessageReject()
[Test]
public void LogonReject()
{
application.fromAdminException = new QuickFix.RejectLogon("Failed Logon");
application.fromAdminException = new QuickFix.RejectLogon("Failed Logon");
Logon();

Assert.That(SENT_LOGOUT());
Expand Down Expand Up @@ -505,7 +505,7 @@ public void TestGapFillOnResend()
public void TestResendSessionLevelReject()
{
Assert.False(session.ResendSessionLevelRejects); // check for correct default
Logon();
Logon();

QuickFix.FIX42.Reject reject = new QuickFix.FIX42.Reject(
new QuickFix.Fields.RefSeqNum(10));
Expand Down Expand Up @@ -545,12 +545,12 @@ public void AssertMicrosecondsInTag(string msgType, int tag, bool shouldHaveMicr
public void TestMillisecondsInSendingTimeStamp()
{
// MS in timestamp should default to Y
Assert.That(session.TimeStampPrecision == QuickFix.Fields.Converters.TimeStampPrecision.Millisecond );
Assert.That(session.TimeStampPrecision == QuickFix.Fields.Converters.TimeStampPrecision.Millisecond);

// Ms should show up
Logon();
AssertMsInTag(QuickFix.Fields.MsgType.LOGON, QuickFix.Fields.Tags.SendingTime, true);

// No ms
session.TimeStampPrecision = QuickFix.Fields.Converters.TimeStampPrecision.Second;
Logon();
Expand Down Expand Up @@ -585,7 +585,7 @@ public void TestMicrosecondsInSendingTimeStamp()
// Less than FIX42 - no microseconds in timestamp, even if you tell it to
sessionID = new QuickFix.SessionID(QuickFix.FixValues.BeginString.FIX40, "SENDER", "TARGET");
session.SessionID = sessionID;
session.TimeStampPrecision = QuickFix.Fields.Converters.TimeStampPrecision.Microsecond;
session.TimeStampPrecision = QuickFix.Fields.Converters.TimeStampPrecision.Microsecond;
Logon40();
Assert.That(responder.msgLookup[QuickFix.Fields.MsgType.LOGON].Count == 3);
AssertMicrosecondsInTag(QuickFix.Fields.MsgType.LOGON, QuickFix.Fields.Tags.SendingTime, false);
Expand All @@ -595,11 +595,11 @@ public void TestMicrosecondsInSendingTimeStamp()
public void TestMillisecondsInOrigSendingTimeStamp()
{
// MS in timestamp should default
Assert.That( session.TimeStampPrecision == QuickFix.Fields.Converters.TimeStampPrecision.Millisecond );
Assert.That(session.TimeStampPrecision == QuickFix.Fields.Converters.TimeStampPrecision.Millisecond);

// Logon first
Logon();

// Do a resend request
SendResendRequest(0, 2);
AssertMsInTag(QuickFix.Fields.MsgType.SEQUENCERESET, QuickFix.Fields.Tags.OrigSendingTime, true);
Expand Down Expand Up @@ -789,7 +789,7 @@ public void TestDoesSessionExist()
QuickFix.SessionID validSessionID = new QuickFix.SessionID("FIX.4.2", "SENDER", "TARGET");

Assert.That(QuickFix.Session.DoesSessionExist(invalidSessionID), Is.EqualTo(false));
Assert.That(QuickFix.Session.DoesSessionExist(validSessionID), Is.EqualTo(true));
Assert.That(QuickFix.Session.DoesSessionExist(validSessionID), Is.EqualTo(true));
}

[Test]
Expand Down Expand Up @@ -845,7 +845,7 @@ public void TestRequiresOrigSendingTime_Y()
Logon();

QuickFix.FIX42.SequenceReset sr = new QuickFix.FIX42.SequenceReset(new QuickFix.Fields.NewSeqNo(5));
sr.GapFillFlag = new QuickFix.Fields.GapFillFlag(true);
sr.GapFillFlag = new QuickFix.Fields.GapFillFlag(false);
sr.Header.SetField(new QuickFix.Fields.PossDupFlag(true));

sr.Header.SetField(new QuickFix.Fields.MsgSeqNum(seqNum--)); // so it triggers DoTargetTooLow code
Expand Down

0 comments on commit c8d46d8

Please sign in to comment.