Skip to content

Commit

Permalink
Speed up slow market test
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenGround0 committed Apr 17, 2023
1 parent 1cfc78c commit fc418a3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
27 changes: 25 additions & 2 deletions actors/market/tests/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,29 @@ pub fn setup() -> MockRuntime {
rt
}

pub fn setup_with_policy(policy: Policy) -> MockRuntime {
let actor_code_cids = HashMap::from([
(OWNER_ADDR, *ACCOUNT_ACTOR_CODE_ID),
(WORKER_ADDR, *ACCOUNT_ACTOR_CODE_ID),
(PROVIDER_ADDR, *MINER_ACTOR_CODE_ID),
(CLIENT_ADDR, *ACCOUNT_ACTOR_CODE_ID),
]);

let rt = MockRuntime {
receiver: STORAGE_MARKET_ACTOR_ADDR,
caller: RefCell::new(SYSTEM_ACTOR_ADDR),
caller_type: RefCell::new(*INIT_ACTOR_CODE_ID),
actor_code_cids: RefCell::new(actor_code_cids),
balance: RefCell::new(TokenAmount::from_whole(10)),
policy,
..Default::default()
};

construct_and_verify(&rt);

rt
}

/// Checks internal invariants of market state asserting none of them are broken.
pub fn check_state(rt: &MockRuntime) {
let (_, acc) = check_state_invariants(
Expand Down Expand Up @@ -757,11 +780,11 @@ pub fn expect_query_network_info(rt: &MockRuntime) {
);
}

pub fn assert_n_good_deals<BS>(dobe: &SetMultimap<BS>, epoch: ChainEpoch, n: isize)
pub fn assert_n_good_deals<BS>(dobe: &SetMultimap<BS>, epoch: ChainEpoch, n: isize, policy: &Policy)
where
BS: fvm_ipld_blockstore::Blockstore,
{
let deal_updates_interval = Policy::default().deal_updates_interval;
let deal_updates_interval = policy.deal_updates_interval;
let mut count = 0;
dobe.for_each(epoch, |id| {
assert_eq!(epoch % deal_updates_interval, (id as i64) % deal_updates_interval);
Expand Down
18 changes: 9 additions & 9 deletions actors/market/tests/market_actor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,12 @@ fn fails_if_withdraw_from_provider_funds_is_not_initiated_by_the_owner_or_worker

#[test]
fn deal_starts_on_day_boundary() {
let deal_updates_interval = Policy::default().deal_updates_interval;
let start_epoch = deal_updates_interval; // 2880
let deal_updates_interval = 101; // small number for testing
let start_epoch = deal_updates_interval;
let end_epoch = start_epoch + 200 * EPOCHS_IN_DAY;
let publish_epoch = ChainEpoch::from(1);

let rt = setup();
let rt = setup_with_policy(Policy { deal_updates_interval, ..Default::default() });
rt.set_epoch(publish_epoch);

for i in 0..(3 * deal_updates_interval) {
Expand All @@ -582,15 +582,15 @@ fn deal_starts_on_day_boundary() {
let store = &rt.store;
let dobe = SetMultimap::from_root(store, &st.deal_ops_by_epoch).unwrap();
for e in deal_updates_interval..(2 * deal_updates_interval) {
assert_n_good_deals(&dobe, e, 3);
assert_n_good_deals(&dobe, e, 3, &rt.policy);
}

// DOBE has no deals scheduled in the previous or next day
for e in 0..deal_updates_interval {
assert_n_good_deals(&dobe, e, 0);
assert_n_good_deals(&dobe, e, 0, &rt.policy);
}
for e in (2 * deal_updates_interval)..(3 * deal_updates_interval) {
assert_n_good_deals(&dobe, e, 0);
assert_n_good_deals(&dobe, e, 0, &rt.policy);
}
}

Expand Down Expand Up @@ -622,11 +622,11 @@ fn deal_starts_partway_through_day() {
let store = &rt.store;
let dobe = SetMultimap::from_root(store, &st.deal_ops_by_epoch).unwrap();
for e in interval..(interval + start_epoch) {
assert_n_good_deals(&dobe, e, 1);
assert_n_good_deals(&dobe, e, 1, &rt.policy);
}
// Nothing scheduled between 0 and interval
for e in 0..interval {
assert_n_good_deals(&dobe, e, 0);
assert_n_good_deals(&dobe, e, 0, &rt.policy);
}

// Now add another 500 deals
Expand All @@ -647,7 +647,7 @@ fn deal_starts_partway_through_day() {
let store = &rt.store;
let dobe = SetMultimap::from_root(store, &st.deal_ops_by_epoch).unwrap();
for e in start_epoch..(start_epoch + 500) {
assert_n_good_deals(&dobe, e, 1);
assert_n_good_deals(&dobe, e, 1, &rt.policy);
}
}

Expand Down

0 comments on commit fc418a3

Please sign in to comment.