Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(neard/tests): reduce boilerplate with intuitive structures #4229

Merged
merged 34 commits into from
Apr 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0541f8c
add structure for rm node launch boilerplate in tests
miraclx Apr 14, 2021
66a83b5
add means to properly handle ctrl-c interrupts
miraclx Apr 14, 2021
f5269b9
test-utils: rm actix: -rt only is sufficient
miraclx Apr 15, 2021
54aaafa
reduce extra nesting by making heavy_test a config on NodeCluster
miraclx Apr 15, 2021
ab88d83
create cluster, then execute, reads better
miraclx Apr 15, 2021
4bafd54
don't forget to stop the system after the test
miraclx Apr 15, 2021
1f65d47
expand NodeCluster use to the rest of rpc_nodes
miraclx Apr 15, 2021
90a7a60
expand NodeCluster to aid its usefulness in run_nodes
miraclx Apr 15, 2021
af1512f
move .heavy() to a variant in the configvariant enum
miraclx Apr 15, 2021
199614a
remove unnecessary is_err line
miraclx Apr 15, 2021
49e8398
SIGINT causes a murderous psychopath to kill all kids
miraclx Apr 15, 2021
7079342
rename mkdir to something more appropriate: mkdirs_with
miraclx Apr 15, 2021
d13e4f4
remove extra spawn within spawned cluster task
miraclx Apr 15, 2021
7ad0294
appropriately rename run_nodes reflecting its implicit heaviness
miraclx Apr 15, 2021
dbdeb7a
rename exec to something more appropriate: exec_until_stop
miraclx Apr 15, 2021
a15e1f7
expand NodeCluster to aid its usefulness in track_shards
miraclx Apr 15, 2021
818de94
register signal handler on first exec call, not init
miraclx Apr 16, 2021
3b8e025
check parent before and after starting nodes
miraclx Apr 16, 2021
c2f09cf
move SIGINT checks to test-utils/near-actix
miraclx Apr 16, 2021
6dace3b
replace actix::spawn with spawn_interruptible in other tests
miraclx Apr 16, 2021
2079fc8
merge NodeCluster::{new,mkdirs_with}: no nodeless clusters
miraclx Apr 16, 2021
a47cd9f
be explicit, unalias spawn_interruptible
miraclx Apr 16, 2021
b9b8050
Vec gets the size_hint, skip the explicit reservation
miraclx Apr 16, 2021
e193250
panic immediately on exec with config issues
miraclx Apr 16, 2021
56fba0d
cluster executors are FnOnce
miraclx Apr 16, 2021
d96f2c9
defer to using uniq assoc methods instead of enum
miraclx Apr 16, 2021
84b967f
typo: received not recieved
miraclx Apr 17, 2021
75df4ea
fix ctrl-c elison on busy blocking threads
miraclx Apr 17, 2021
19d97cd
manually define assoc methods, skip the use of macro
miraclx Apr 17, 2021
4401057
implicitly treat every NodeCluster executed test as a heavy test
miraclx Apr 17, 2021
9b658dc
init NodeCluster with node_count, instead of capacity
miraclx Apr 17, 2021
8c9ed4a
rename assoc methods, use properly named setters
miraclx Apr 17, 2021
444d5c9
Merge branch 'master' into neard-tests-structured-boilerplate
frol Apr 17, 2021
1532070
fix last merge: update changes from master
miraclx Apr 17, 2021
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
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 90 additions & 0 deletions neard/tests/node_cluster.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use futures::future;

use near_actix_test_utils::{run_actix_until_stop, spawn_interruptible};
use near_client::{ClientActor, ViewClientActor};
use near_primitives::types::{BlockHeight, BlockHeightDelta, NumSeats, NumShards};
use testlib::{start_nodes, test_helpers::heavy_test};

#[derive(Debug, Default)]
pub struct NodeCluster {
dirs: Vec<tempfile::TempDir>,
num_shards: Option<NumShards>,
num_validator_seats: Option<NumSeats>,
num_lightclient: Option<usize>,
epoch_length: Option<BlockHeightDelta>,
genesis_height: Option<BlockHeight>,
}

impl NodeCluster {
pub fn new<F: Fn(usize) -> String>(node_count: usize, gen_dirname: F) -> Self {
Self {
dirs: (0..node_count)
.map(|index| {
tempfile::Builder::new().prefix(&gen_dirname(index)).tempdir().unwrap()
})
.collect(),
..Default::default()
}
}

pub fn set_num_shards(mut self, n: NumShards) -> Self {
self.num_shards = Some(n);
self
}

pub fn set_num_validator_seats(mut self, n: NumSeats) -> Self {
self.num_validator_seats = Some(n);
self
}

pub fn set_num_lightclients(mut self, n: usize) -> Self {
self.num_lightclient = Some(n);
self
}

pub fn set_epoch_length(mut self, l: BlockHeightDelta) -> Self {
self.epoch_length = Some(l);
self
}

pub fn set_genesis_height(mut self, h: BlockHeight) -> Self {
self.genesis_height = Some(h);
self
}

pub fn exec_until_stop<F, R>(self, f: F)
where
R: future::Future<Output = ()> + 'static,
F: FnOnce(
near_chain_configs::Genesis,
Vec<String>,
Vec<(
actix::Addr<ClientActor>,
actix::Addr<ViewClientActor>,
Vec<actix_rt::ArbiterHandle>,
)>,
) -> R,
{
assert!(!self.dirs.is_empty(), "cluster config: expected a non-zero number of directories");
let (num_shards, num_validator_seats, num_lightclient, epoch_length, genesis_height) = (
self.num_shards.expect("cluster config: [num_shards] undefined"),
self.num_validator_seats.expect("cluster config: [num_validator_seats] undefined"),
self.num_lightclient.expect("cluster config: [num_lightclient] undefined"),
self.epoch_length.expect("cluster config: [epoch_length] undefined"),
self.genesis_height.expect("cluster config: [genesis_height] undefined"),
);
heavy_test(|| {
run_actix_until_stop(async {
let (genesis, rpc_addrs, clients) = start_nodes(
num_shards,
&self.dirs,
num_validator_seats,
num_lightclient,
epoch_length,
genesis_height,
);
spawn_interruptible(f(genesis, rpc_addrs, clients));
});
});
}
}
Loading