-
Notifications
You must be signed in to change notification settings - Fork 660
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(resharding): Increase epoch length for shard shuffling (#12674)
Some resharding tests were failing with single shard tracking enabled because of epoch length was sligthly too short. Under the hood, if we are close to epoch length (4 blocks or less), we forward transactions to chunk producer for the next epoch too. But if the epoch length is 6, it means the chunk producer has only 2 blocks to catchup before it is supposed to start accepting transactions for the new shard. In such case, `TX_CHECK_BLOCKS_AFTER_RESHARDING` needs also be increased. **Changes:** This PR sets `INCREASED_EPOCH_LENGTH: 8` for these tests. For remaining tests, I keep the old `DEFAULT_EPOCH_LENGTH: 6`, to test potentially more corner cases, and some tests seem to be designed with this specific epoch length in mind. `TX_CHECK_BLOCKS_AFTER_RESHARDING ` is increased to almost max (`epoch_length - 2`). Loop actions are slightly refactored, introducing `LoopAction` to make sure these actions actually succeed before the test is over. It happened to me several times they did not, if some parameter was changed.
- Loading branch information
Showing
4 changed files
with
147 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use std::cell::Cell; | ||
use std::rc::Rc; | ||
|
||
use near_async::test_loop::data::TestLoopData; | ||
use near_primitives::types::AccountId; | ||
|
||
use crate::test_loop::env::TestData; | ||
|
||
/// Signature of functions callable from inside the inner loop of a testloop test. | ||
pub(crate) type LoopActionFn = Box<dyn Fn(&[TestData], &mut TestLoopData, AccountId)>; | ||
|
||
/// A wrapper for a callable (action) to be used inside a testloop test. | ||
/// | ||
/// The action has two failure modes: | ||
/// 1. It can fail during an execution of the callable (e.g. assert failure). | ||
/// 2. The `succeeded` has never been set by the action and the testloop test is over. | ||
/// | ||
/// The expectation is that `succeeded` would eventually be set to true by some iteration of `action_fn`. | ||
pub(crate) struct LoopAction { | ||
action_fn: LoopActionFn, | ||
started: Cell<bool>, | ||
succeeded: Rc<Cell<bool>>, | ||
} | ||
|
||
impl LoopAction { | ||
/// Returns a pair of pointers to the same flag, initially set to false. | ||
/// To be used for a succees flag that is shared between `LoopAction` and its `LoopActionFn`. | ||
pub fn shared_success_flag() -> (Rc<Cell<bool>>, Rc<Cell<bool>>) { | ||
let flag = Rc::new(Cell::new(false)); | ||
(flag.clone(), flag) | ||
} | ||
} | ||
|
||
/// Current status for a `LoopAction`. | ||
#[derive(Debug)] | ||
pub enum LoopActionStatus { | ||
/// The action has never been called. | ||
NotStarted, | ||
/// The action has been called, but it has not set the `succeeded` flag yet. | ||
Started, | ||
/// The `succeeded` flag has been set. | ||
Succeeded, | ||
} | ||
|
||
impl LoopAction { | ||
/// The `succeeded` flag should be shared with `action_fn` that will update the flag at some point. | ||
pub fn new(action_fn: LoopActionFn, succeeded: Rc<Cell<bool>>) -> LoopAction { | ||
LoopAction { action_fn, started: Cell::new(false), succeeded } | ||
} | ||
|
||
/// Call the action callable with provided arguments. | ||
pub fn call( | ||
&self, | ||
test_data: &[TestData], | ||
test_loop_data: &mut TestLoopData, | ||
account_id: AccountId, | ||
) { | ||
self.started.set(true); | ||
(self.action_fn)(test_data, test_loop_data, account_id) | ||
} | ||
|
||
/// Return the current status of the loop action. | ||
pub fn get_status(&self) -> LoopActionStatus { | ||
if self.succeeded.get() { | ||
return LoopActionStatus::Succeeded; | ||
} | ||
if self.started.get() { | ||
return LoopActionStatus::Started; | ||
} | ||
LoopActionStatus::NotStarted | ||
} | ||
} |
Oops, something went wrong.