Skip to content

Commit 5b68992

Browse files
committed
reset seq numbers if elapsed in between checks
1 parent 29c47d4 commit 5b68992

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed

internal/session_settings.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type SessionSettings struct {
2121
TimeZone *time.Location
2222
ResetSeqTime time.Time
2323
EnableResetSeqTime bool
24+
LastCheckedResetSeqTime time.Time
2425

2526
// Required on logon for FIX.T.1 messages.
2627
DefaultApplVerID string

session_factory.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ func (f sessionFactory) newSession(
388388
}
389389
s.EnableResetSeqTime = true
390390
s.ResetSeqTime = seqTime
391+
s.LastCheckedResetSeqTime = seqTime
391392
} else {
392393
s.EnableResetSeqTime = false
393394
}

session_state.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,13 @@ func (sm *stateMachine) CheckSessionTime(session *session, now time.Time) {
157157

158158
func (sm *stateMachine) CheckResetTime(session *session, now time.Time) {
159159
if session.EnableResetSeqTime {
160-
if session.ResetSeqTime.Hour() == now.Hour() &&
161-
session.ResetSeqTime.Minute() == now.Minute() &&
162-
session.ResetSeqTime.Second() == now.Second() {
160+
// The last time we checked the reset time was before the configured reset time
161+
// and the current time is after the configured reset time.
162+
// so that means we've crossed the reset time boundary.
163+
if session.LastCheckedResetSeqTime.Before(session.ResetSeqTime) && now.After(session.ResetSeqTime) && session.stateMachine.State.IsConnected() {
163164
session.sendLogonInReplyTo(true, nil)
164165
}
166+
session.LastCheckedResetSeqTime = now
165167
}
166168
}
167169

session_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,3 +1052,59 @@ func (s *SessionSuite) TestSeqNumResetTimeDisconnected() {
10521052
s.NextSenderMsgSeqNum(2)
10531053
s.NextTargetMsgSeqNum(2)
10541054
}
1055+
1056+
func (s *SessionSuite) TestSeqNumResetTimeAfterElapse() {
1057+
s.session.State = logonState{}
1058+
before := time.Now().UTC()
1059+
resetTime := time.Now().UTC().Add(time.Second * 2)
1060+
after := resetTime.Add(time.Second * 1)
1061+
s.session.ResetSeqTime = resetTime
1062+
s.session.EnableResetSeqTime = true
1063+
1064+
s.NextSenderMsgSeqNum(1)
1065+
s.NextTargetMsgSeqNum(1)
1066+
s.IncrNextTargetMsgSeqNum()
1067+
s.IncrNextSenderMsgSeqNum()
1068+
s.NextSenderMsgSeqNum(2)
1069+
s.NextTargetMsgSeqNum(2)
1070+
1071+
s.MockApp.On("ToAdmin")
1072+
s.session.CheckResetTime(s.session, before)
1073+
s.NextSenderMsgSeqNum(2)
1074+
s.NextTargetMsgSeqNum(2)
1075+
1076+
s.session.LastCheckedResetSeqTime = before
1077+
s.session.CheckResetTime(s.session, after)
1078+
s.NextSenderMsgSeqNum(2)
1079+
s.NextTargetMsgSeqNum(1)
1080+
}
1081+
1082+
func (s *SessionSuite) TestSeqNumResetTimeNotAfterDisconnect() {
1083+
s.session.State = logonState{}
1084+
before := time.Now().UTC()
1085+
resetTime := before.Add(time.Second * 2)
1086+
after := resetTime.Add(time.Second * 1)
1087+
s.session.ResetSeqTime = resetTime
1088+
s.session.EnableResetSeqTime = true
1089+
1090+
s.NextSenderMsgSeqNum(1)
1091+
s.NextTargetMsgSeqNum(1)
1092+
s.IncrNextTargetMsgSeqNum()
1093+
s.IncrNextSenderMsgSeqNum()
1094+
s.NextSenderMsgSeqNum(2)
1095+
s.NextTargetMsgSeqNum(2)
1096+
1097+
s.MockApp.On("ToAdmin")
1098+
s.session.CheckResetTime(s.session, before)
1099+
s.NextSenderMsgSeqNum(2)
1100+
s.NextTargetMsgSeqNum(2)
1101+
1102+
s.session.onAdmin(stopReq{})
1103+
s.Disconnected()
1104+
s.Stopped()
1105+
1106+
s.session.LastCheckedResetSeqTime = before
1107+
s.session.CheckResetTime(s.session, after)
1108+
s.NextSenderMsgSeqNum(2)
1109+
s.NextTargetMsgSeqNum(2)
1110+
}

0 commit comments

Comments
 (0)