Skip to content

Commit 2a77e08

Browse files
authored
test: add stage name to test suite functions (#934)
1 parent 013eb51 commit 2a77e08

File tree

9 files changed

+155
-148
lines changed

9 files changed

+155
-148
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/stages/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ tokio-stream = "0.1.10"
4646
tempfile = "3.3.0"
4747
assert_matches = "1.5.0"
4848
rand = "0.8.5"
49+
paste = "1.0"

crates/stages/src/stages/bodies.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ mod tests {
278278
use std::collections::HashMap;
279279
use test_utils::*;
280280

281-
stage_test_suite_ext!(BodyTestRunner);
281+
stage_test_suite_ext!(BodyTestRunner, body);
282282

283283
/// Checks that the stage downloads at most `batch_size` blocks.
284284
#[tokio::test]

crates/stages/src/stages/hashing_account.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ mod tests {
175175
use reth_provider::insert_canonical_block;
176176
use test_utils::*;
177177

178-
stage_test_suite_ext!(AccountHashingTestRunner);
178+
stage_test_suite_ext!(AccountHashingTestRunner, account_hashing);
179179

180180
#[tokio::test]
181181
async fn execute_below_clean_threshold() {

crates/stages/src/stages/hashing_storage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ mod tests {
223223
SealedBlock, StorageEntry, Transaction, TransactionKind, TxLegacy, H256, U256,
224224
};
225225

226-
stage_test_suite_ext!(StorageHashingTestRunner);
226+
stage_test_suite_ext!(StorageHashingTestRunner, storage_hashing);
227227

228228
/// Execute with low clean threshold so as to hash whole storage
229229
#[tokio::test]

crates/stages/src/stages/headers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ mod tests {
295295
use reth_interfaces::{p2p::error::RequestError, test_utils::generators::random_header};
296296
use test_runner::HeadersTestRunner;
297297

298-
stage_test_suite!(HeadersTestRunner);
298+
stage_test_suite!(HeadersTestRunner, headers);
299299

300300
/// Check that the execution errors on empty database or
301301
/// prev progress missing from the database.

crates/stages/src/stages/sender_recovery.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ mod tests {
137137
TestTransaction, UnwindStageTestRunner, PREV_STAGE_ID,
138138
};
139139

140-
stage_test_suite_ext!(SenderRecoveryTestRunner);
140+
stage_test_suite_ext!(SenderRecoveryTestRunner, sender_recovery);
141141

142142
/// Execute a block range with a single transaction
143143
#[tokio::test]

crates/stages/src/stages/total_difficulty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ mod tests {
9595
TestTransaction, UnwindStageTestRunner, PREV_STAGE_ID,
9696
};
9797

98-
stage_test_suite_ext!(TotalDifficultyTestRunner);
98+
stage_test_suite_ext!(TotalDifficultyTestRunner, total_difficulty);
9999

100100
#[tokio::test]
101101
async fn execute_with_intermediate_commit() {

crates/stages/src/test_utils/macros.rs

Lines changed: 147 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1,153 +1,158 @@
11
macro_rules! stage_test_suite {
2-
($runner:ident) => {
3-
/// Check that the execution is short-circuited if the database is empty.
4-
#[tokio::test]
5-
async fn execute_empty_db() {
6-
// Set up the runner
7-
let runner = $runner::default();
8-
9-
// Execute the stage with empty database
10-
let input = crate::stage::ExecInput::default();
11-
12-
// Run stage execution
13-
let result = runner.execute(input).await;
14-
// Check that the result is returned and the stage does not panic.
15-
// The return result with empty db is stage-specific.
16-
assert_matches::assert_matches!(result, Ok(_));
17-
18-
// Validate the stage execution
19-
assert!(runner.validate_execution(input, result.unwrap().ok()).is_ok(), "execution validation");
20-
}
21-
22-
// Run the complete stage execution flow.
23-
#[tokio::test]
24-
async fn execute() {
25-
let (previous_stage, stage_progress) = (500, 100);
26-
27-
// Set up the runner
28-
let mut runner = $runner::default();
29-
let input = crate::stage::ExecInput {
30-
previous_stage: Some((crate::test_utils::PREV_STAGE_ID, previous_stage)),
31-
stage_progress: Some(stage_progress),
32-
};
33-
let seed = runner.seed_execution(input).expect("failed to seed");
34-
let rx = runner.execute(input);
35-
36-
// Run `after_execution` hook
37-
runner.after_execution(seed).await.expect("failed to run after execution hook");
38-
39-
// Assert the successful result
40-
let result = rx.await.unwrap();
41-
assert_matches::assert_matches!(
42-
result,
43-
Ok(ExecOutput { done, stage_progress })
44-
if done && stage_progress == previous_stage
45-
);
46-
47-
// Validate the stage execution
48-
assert!(runner.validate_execution(input, result.ok()).is_ok(), "execution validation");
49-
}
50-
51-
// Check that unwind does not panic on no new entries within the input range.
52-
#[tokio::test]
53-
async fn unwind_no_new_entries() {
54-
// Set up the runner
55-
let mut runner = $runner::default();
56-
let input = crate::stage::UnwindInput::default();
57-
58-
// Seed the database
59-
runner.seed_execution(crate::stage::ExecInput::default()).expect("failed to seed");
60-
61-
// Run stage unwind
62-
let rx = runner.unwind(input).await;
63-
assert_matches::assert_matches!(
64-
rx,
65-
Ok(UnwindOutput { stage_progress }) if stage_progress == input.unwind_to
66-
);
67-
68-
// Validate the stage unwind
69-
assert!(runner.validate_unwind(input).is_ok(), "unwind validation");
70-
}
71-
72-
// Run complete execute and unwind flow.
73-
#[tokio::test]
74-
async fn unwind() {
75-
let (previous_stage, stage_progress) = (500, 100);
76-
77-
// Set up the runner
78-
let mut runner = $runner::default();
79-
let execute_input = crate::stage::ExecInput {
80-
previous_stage: Some((crate::test_utils::PREV_STAGE_ID, previous_stage)),
81-
stage_progress: Some(stage_progress),
82-
};
83-
let seed = runner.seed_execution(execute_input).expect("failed to seed");
84-
85-
// Run stage execution
86-
let rx = runner.execute(execute_input);
87-
runner.after_execution(seed).await.expect("failed to run after execution hook");
88-
89-
// Assert the successful execution result
90-
let result = rx.await.unwrap();
91-
assert_matches::assert_matches!(
92-
result,
93-
Ok(ExecOutput { done, stage_progress })
94-
if done && stage_progress == previous_stage
95-
);
96-
assert!(runner.validate_execution(execute_input, result.ok()).is_ok(), "execution validation");
97-
98-
// Run stage unwind
99-
let unwind_input = crate::stage::UnwindInput {
100-
unwind_to: stage_progress, stage_progress: previous_stage, bad_block: None,
101-
};
102-
let rx = runner.unwind(unwind_input).await;
103-
104-
// Assert the successful unwind result
105-
assert_matches::assert_matches!(
106-
rx,
107-
Ok(UnwindOutput { stage_progress }) if stage_progress == unwind_input.unwind_to
108-
);
109-
110-
// Validate the stage unwind
111-
assert!(runner.validate_unwind(unwind_input).is_ok(), "unwind validation");
2+
($runner:ident, $name:ident) => {
3+
4+
paste::item! {
5+
/// Check that the execution is short-circuited if the database is empty.
6+
#[tokio::test]
7+
async fn [< execute_empty_db_ $name>] () {
8+
// Set up the runner
9+
let runner = $runner::default();
10+
11+
// Execute the stage with empty database
12+
let input = crate::stage::ExecInput::default();
13+
14+
// Run stage execution
15+
let result = runner.execute(input).await;
16+
// Check that the result is returned and the stage does not panic.
17+
// The return result with empty db is stage-specific.
18+
assert_matches::assert_matches!(result, Ok(_));
19+
20+
// Validate the stage execution
21+
assert!(runner.validate_execution(input, result.unwrap().ok()).is_ok(), "execution validation");
22+
}
23+
24+
// Run the complete stage execution flow.
25+
#[tokio::test]
26+
async fn [< execute_ $name>] () {
27+
let (previous_stage, stage_progress) = (500, 100);
28+
29+
// Set up the runner
30+
let mut runner = $runner::default();
31+
let input = crate::stage::ExecInput {
32+
previous_stage: Some((crate::test_utils::PREV_STAGE_ID, previous_stage)),
33+
stage_progress: Some(stage_progress),
34+
};
35+
let seed = runner.seed_execution(input).expect("failed to seed");
36+
let rx = runner.execute(input);
37+
38+
// Run `after_execution` hook
39+
runner.after_execution(seed).await.expect("failed to run after execution hook");
40+
41+
// Assert the successful result
42+
let result = rx.await.unwrap();
43+
assert_matches::assert_matches!(
44+
result,
45+
Ok(ExecOutput { done, stage_progress })
46+
if done && stage_progress == previous_stage
47+
);
48+
49+
// Validate the stage execution
50+
assert!(runner.validate_execution(input, result.ok()).is_ok(), "execution validation");
51+
}
52+
53+
// Check that unwind does not panic on no new entries within the input range.
54+
#[tokio::test]
55+
async fn [< unwind_no_new_entries_ $name>] () {
56+
// Set up the runner
57+
let mut runner = $runner::default();
58+
let input = crate::stage::UnwindInput::default();
59+
60+
// Seed the database
61+
runner.seed_execution(crate::stage::ExecInput::default()).expect("failed to seed");
62+
63+
// Run stage unwind
64+
let rx = runner.unwind(input).await;
65+
assert_matches::assert_matches!(
66+
rx,
67+
Ok(UnwindOutput { stage_progress }) if stage_progress == input.unwind_to
68+
);
69+
70+
// Validate the stage unwind
71+
assert!(runner.validate_unwind(input).is_ok(), "unwind validation");
72+
}
73+
74+
// Run complete execute and unwind flow.
75+
#[tokio::test]
76+
async fn [< unwind_ $name>] () {
77+
let (previous_stage, stage_progress) = (500, 100);
78+
79+
// Set up the runner
80+
let mut runner = $runner::default();
81+
let execute_input = crate::stage::ExecInput {
82+
previous_stage: Some((crate::test_utils::PREV_STAGE_ID, previous_stage)),
83+
stage_progress: Some(stage_progress),
84+
};
85+
let seed = runner.seed_execution(execute_input).expect("failed to seed");
86+
87+
// Run stage execution
88+
let rx = runner.execute(execute_input);
89+
runner.after_execution(seed).await.expect("failed to run after execution hook");
90+
91+
// Assert the successful execution result
92+
let result = rx.await.unwrap();
93+
assert_matches::assert_matches!(
94+
result,
95+
Ok(ExecOutput { done, stage_progress })
96+
if done && stage_progress == previous_stage
97+
);
98+
assert!(runner.validate_execution(execute_input, result.ok()).is_ok(), "execution validation");
99+
100+
// Run stage unwind
101+
let unwind_input = crate::stage::UnwindInput {
102+
unwind_to: stage_progress, stage_progress: previous_stage, bad_block: None,
103+
};
104+
let rx = runner.unwind(unwind_input).await;
105+
106+
// Assert the successful unwind result
107+
assert_matches::assert_matches!(
108+
rx,
109+
Ok(UnwindOutput { stage_progress }) if stage_progress == unwind_input.unwind_to
110+
);
111+
112+
// Validate the stage unwind
113+
assert!(runner.validate_unwind(unwind_input).is_ok(), "unwind validation");
114+
}
112115
}
113116
};
114117
}
115118

116119
// `execute_already_reached_target` is not suitable for the headers stage thus
117120
// included in the test suite extension
118121
macro_rules! stage_test_suite_ext {
119-
($runner:ident) => {
120-
crate::test_utils::stage_test_suite!($runner);
121-
122-
/// Check that the execution is short-circuited if the target was already reached.
123-
#[tokio::test]
124-
async fn execute_already_reached_target() {
125-
let stage_progress = 1000;
126-
127-
// Set up the runner
128-
let mut runner = $runner::default();
129-
let input = crate::stage::ExecInput {
130-
previous_stage: Some((crate::test_utils::PREV_STAGE_ID, stage_progress)),
131-
stage_progress: Some(stage_progress),
132-
};
133-
let seed = runner.seed_execution(input).expect("failed to seed");
134-
135-
// Run stage execution
136-
let rx = runner.execute(input);
137-
138-
// Run `after_execution` hook
139-
runner.after_execution(seed).await.expect("failed to run after execution hook");
140-
141-
// Assert the successful result
142-
let result = rx.await.unwrap();
143-
assert_matches::assert_matches!(
144-
result,
145-
Ok(ExecOutput { done, stage_progress })
146-
if done && stage_progress == stage_progress
147-
);
148-
149-
// Validate the stage execution
150-
assert!(runner.validate_execution(input, result.ok()).is_ok(), "execution validation");
122+
($runner:ident, $name:ident) => {
123+
crate::test_utils::stage_test_suite!($runner, $name);
124+
125+
paste::item! {
126+
/// Check that the execution is short-circuited if the target was already reached.
127+
#[tokio::test]
128+
async fn [< execute_already_reached_target_ $name>] () {
129+
let stage_progress = 1000;
130+
131+
// Set up the runner
132+
let mut runner = $runner::default();
133+
let input = crate::stage::ExecInput {
134+
previous_stage: Some((crate::test_utils::PREV_STAGE_ID, stage_progress)),
135+
stage_progress: Some(stage_progress),
136+
};
137+
let seed = runner.seed_execution(input).expect("failed to seed");
138+
139+
// Run stage execution
140+
let rx = runner.execute(input);
141+
142+
// Run `after_execution` hook
143+
runner.after_execution(seed).await.expect("failed to run after execution hook");
144+
145+
// Assert the successful result
146+
let result = rx.await.unwrap();
147+
assert_matches::assert_matches!(
148+
result,
149+
Ok(ExecOutput { done, stage_progress })
150+
if done && stage_progress == stage_progress
151+
);
152+
153+
// Validate the stage execution
154+
assert!(runner.validate_execution(input, result.ok()).is_ok(), "execution validation");
155+
}
151156
}
152157
};
153158
}

0 commit comments

Comments
 (0)