Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ impl Agent {
));

// Spawn the Pythd API Server
jhs.push(rpc::spawn_server(
jhs.push(tokio::spawn(rpc::run(
self.config.pythd_api_server.clone(),
logger.clone(),
pythd_adapter_tx,
shutdown_rx,
logger.clone(),
));
)));

// Spawn the metrics server
jhs.push(tokio::spawn(metrics::MetricsServer::spawn(
Expand Down
170 changes: 83 additions & 87 deletions src/agent/market_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ use {
Utc,
},
chrono_tz::Tz,
proptest::{
arbitrary::any,
prop_compose,
proptest,
},
std::{
fmt::Display,
str::FromStr,
Expand All @@ -42,7 +37,6 @@ use {
},
};


/// Helper time value representing 24:00:00 as 00:00:00 minus 1
/// nanosecond (underflowing to 23:59:59.999(...) ). While chrono
/// has this value internally exposed as NaiveTime::MAX, it is not
Expand All @@ -51,7 +45,6 @@ const MAX_TIME_INSTANT: NaiveTime = NaiveTime::MIN
.overflowing_sub_signed(Duration::nanoseconds(1))
.0;


#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MarketSchedule {
pub timezone: Tz,
Expand Down Expand Up @@ -154,7 +147,6 @@ impl From<LegacySchedule> for MarketSchedule {
}
}


#[derive(Clone, Debug, Eq, PartialEq)]
pub struct HolidayDaySchedule {
pub month: u32,
Expand Down Expand Up @@ -198,7 +190,6 @@ impl Display for HolidayDaySchedule {
}
}


#[derive(Clone, Debug, Eq, PartialEq, Copy)]
pub enum ScheduleDayKind {
Open,
Expand Down Expand Up @@ -286,6 +277,11 @@ mod tests {
use {
super::*,
chrono::NaiveDateTime,
proptest::{
arbitrary::any,
prop_compose,
proptest,
},
};

#[test]
Expand Down Expand Up @@ -478,98 +474,98 @@ mod tests {

Ok(())
}
}

prop_compose! {
fn schedule_day_kind()(
r in any::<u8>(),
t1 in any::<u32>(),
t2 in any::<u32>(),
) -> ScheduleDayKind {
match r % 3 {
0 => ScheduleDayKind::Open,
1 => ScheduleDayKind::Closed,
_ => ScheduleDayKind::TimeRange(
NaiveTime::from_hms_opt(t1 % 24, t1 / 24 % 60, 0).unwrap(),
NaiveTime::from_hms_opt(t2 % 24, t2 / 24 % 60, 0).unwrap(),
),
prop_compose! {
fn schedule_day_kind()(
r in any::<u8>(),
t1 in any::<u32>(),
t2 in any::<u32>(),
) -> ScheduleDayKind {
match r % 3 {
0 => ScheduleDayKind::Open,
1 => ScheduleDayKind::Closed,
_ => ScheduleDayKind::TimeRange(
NaiveTime::from_hms_opt(t1 % 24, t1 / 24 % 60, 0).unwrap(),
NaiveTime::from_hms_opt(t2 % 24, t2 / 24 % 60, 0).unwrap(),
),
}
}
}
}

prop_compose! {
fn holiday_day_schedule()(
m in 1..=12u32,
d in 1..=31u32,
s in schedule_day_kind(),
) -> HolidayDaySchedule {
HolidayDaySchedule {
month: m,
day: d,
kind: s,
prop_compose! {
fn holiday_day_schedule()(
m in 1..=12u32,
d in 1..=31u32,
s in schedule_day_kind(),
) -> HolidayDaySchedule {
HolidayDaySchedule {
month: m,
day: d,
kind: s,
}
}
}
}

prop_compose! {
fn market_schedule()(
tz in proptest::sample::select(vec![
Tz::UTC,
Tz::America__New_York,
Tz::America__Los_Angeles,
Tz::America__Chicago,
Tz::Singapore,
Tz::Australia__Sydney,
]),
weekly_schedule in proptest::collection::vec(schedule_day_kind(), 7..=7),
holidays in proptest::collection::vec(holiday_day_schedule(), 0..12),
) -> MarketSchedule {
MarketSchedule {
timezone: tz,
weekly_schedule,
holidays,
prop_compose! {
fn market_schedule()(
tz in proptest::sample::select(vec![
Tz::UTC,
Tz::America__New_York,
Tz::America__Los_Angeles,
Tz::America__Chicago,
Tz::Singapore,
Tz::Australia__Sydney,
]),
weekly_schedule in proptest::collection::vec(schedule_day_kind(), 7..=7),
holidays in proptest::collection::vec(holiday_day_schedule(), 0..12),
) -> MarketSchedule {
MarketSchedule {
timezone: tz,
weekly_schedule,
holidays,
}
}
}
}

// Matches C or O or hhmm-hhmm with 24-hour time
const VALID_SCHEDULE_DAY_KIND_REGEX: &str =
"C|O|([01][1-9]|2[0-3])([0-5][0-9])-([01][1-9]|2[0-3])([0-5][0-9])";
// Matches C or O or hhmm-hhmm with 24-hour time
const VALID_SCHEDULE_DAY_KIND_REGEX: &str =
"C|O|([01][1-9]|2[0-3])([0-5][0-9])-([01][1-9]|2[0-3])([0-5][0-9])";

// Matches MMDD with MM and DD being 01-12 and 01-31 respectively
const VALID_MONTH_DAY_REGEX: &str = "(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])";
// Matches MMDD with MM and DD being 01-12 and 01-31 respectively
const VALID_MONTH_DAY_REGEX: &str = "(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])";

proptest!(
#[test]
fn doesnt_crash(s in "\\PC*") {
_ = s.parse::<MarketSchedule>();
_ = s.parse::<HolidayDaySchedule>();
_ = s.parse::<ScheduleDayKind>();
}
proptest!(
#[test]
fn doesnt_crash(s in "\\PC*") {
_ = s.parse::<MarketSchedule>();
_ = s.parse::<HolidayDaySchedule>();
_ = s.parse::<ScheduleDayKind>();
}

#[test]
fn parse_valid_schedule_day_kind(s in VALID_SCHEDULE_DAY_KIND_REGEX) {
assert!(s.parse::<ScheduleDayKind>().is_ok());
}
#[test]
fn parse_valid_schedule_day_kind(s in VALID_SCHEDULE_DAY_KIND_REGEX) {
assert!(s.parse::<ScheduleDayKind>().is_ok());
}

#[test]
fn test_valid_schedule_day_kind(s in schedule_day_kind()) {
assert_eq!(s, s.to_string().parse::<ScheduleDayKind>().unwrap());
}
#[test]
fn test_valid_schedule_day_kind(s in schedule_day_kind()) {
assert_eq!(s, s.to_string().parse::<ScheduleDayKind>().unwrap());
}

#[test]
fn parse_valid_holiday_day_schedule(s in VALID_SCHEDULE_DAY_KIND_REGEX, d in VALID_MONTH_DAY_REGEX) {
let valid_holiday_day = format!("{}/{}", d, s);
assert!(valid_holiday_day.parse::<HolidayDaySchedule>().is_ok());
}
#[test]
fn parse_valid_holiday_day_schedule(s in VALID_SCHEDULE_DAY_KIND_REGEX, d in VALID_MONTH_DAY_REGEX) {
let valid_holiday_day = format!("{}/{}", d, s);
assert!(valid_holiday_day.parse::<HolidayDaySchedule>().is_ok());
}

#[test]
fn test_valid_holiday_day_schedule(s in holiday_day_schedule()) {
assert_eq!(s, s.to_string().parse::<HolidayDaySchedule>().unwrap());
}
#[test]
fn test_valid_holiday_day_schedule(s in holiday_day_schedule()) {
assert_eq!(s, s.to_string().parse::<HolidayDaySchedule>().unwrap());
}

#[test]
fn test_valid_market_schedule(s in market_schedule()) {
assert_eq!(s, s.to_string().parse::<MarketSchedule>().unwrap());
}
);
#[test]
fn test_valid_market_schedule(s in market_schedule()) {
assert_eq!(s, s.to_string().parse::<MarketSchedule>().unwrap());
}
);
}
Loading