|
1 | 1 | 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 | + } |
112 | 115 | } |
113 | 116 | }; |
114 | 117 | } |
115 | 118 |
|
116 | 119 | // `execute_already_reached_target` is not suitable for the headers stage thus |
117 | 120 | // included in the test suite extension |
118 | 121 | 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 | + } |
151 | 156 | } |
152 | 157 | }; |
153 | 158 | } |
|
0 commit comments