Skip to content

Commit a696d40

Browse files
committed
Add a couple of tests to de-befuddle myself
1 parent ea1b48d commit a696d40

File tree

2 files changed

+80
-3
lines changed

2 files changed

+80
-3
lines changed

polkadot/node/core/pvf/tests/it/adder.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ async fn execute_bad_block_on_parent() {
100100

101101
let host = TestHost::new();
102102

103-
let _ret = host
103+
let _err = host
104104
.validate_candidate(
105105
adder::wasm_binary_unwrap(),
106106
ValidationParams {
@@ -145,3 +145,37 @@ async fn stress_spawn() {
145145

146146
futures::future::join_all((0..100).map(|_| execute(host.clone()))).await;
147147
}
148+
149+
// With one worker, run multiple execution jobs serially. They should not conflict.
150+
#[tokio::test]
151+
async fn execute_can_run_serially() {
152+
let host = std::sync::Arc::new(TestHost::new_with_config(|cfg| {
153+
cfg.execute_workers_max_num = 1;
154+
}));
155+
156+
async fn execute(host: std::sync::Arc<TestHost>) {
157+
let parent_head = HeadData { number: 0, parent_hash: [0; 32], post_state: hash_state(0) };
158+
let block_data = BlockData { state: 0, add: 512 };
159+
let ret = host
160+
.validate_candidate(
161+
adder::wasm_binary_unwrap(),
162+
ValidationParams {
163+
parent_head: GenericHeadData(parent_head.encode()),
164+
block_data: GenericBlockData(block_data.encode()),
165+
relay_parent_number: 1,
166+
relay_parent_storage_root: Default::default(),
167+
},
168+
Default::default(),
169+
)
170+
.await
171+
.unwrap();
172+
173+
let new_head = HeadData::decode(&mut &ret.head_data.0[..]).unwrap();
174+
175+
assert_eq!(new_head.number, 1);
176+
assert_eq!(new_head.parent_hash, parent_head.hash());
177+
assert_eq!(new_head.post_state, hash_state(512));
178+
}
179+
180+
futures::future::join_all((0..5).map(|_| execute(host.clone()))).await;
181+
}

polkadot/node/core/pvf/tests/it/main.rs

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
use assert_matches::assert_matches;
1919
use parity_scale_codec::Encode as _;
2020
use polkadot_node_core_pvf::{
21-
start, Config, InvalidCandidate, Metrics, PrepareJobKind, PvfPrepData, ValidationError,
22-
ValidationHost, JOB_TIMEOUT_WALL_CLOCK_FACTOR,
21+
start, Config, InvalidCandidate, Metrics, PrepareError, PrepareJobKind, PrepareStats,
22+
PvfPrepData, ValidationError, ValidationHost, JOB_TIMEOUT_WALL_CLOCK_FACTOR,
2323
};
2424
use polkadot_parachain_primitives::primitives::{BlockData, ValidationParams, ValidationResult};
2525
use polkadot_primitives::ExecutorParams;
@@ -70,6 +70,33 @@ impl TestHost {
7070
Self { cache_dir, host: Mutex::new(host) }
7171
}
7272

73+
async fn precheck_pvf(
74+
&self,
75+
code: &[u8],
76+
executor_params: ExecutorParams,
77+
) -> Result<PrepareStats, PrepareError> {
78+
let (result_tx, result_rx) = futures::channel::oneshot::channel();
79+
80+
let code = sp_maybe_compressed_blob::decompress(code, 16 * 1024 * 1024)
81+
.expect("Compression works");
82+
83+
self.host
84+
.lock()
85+
.await
86+
.precheck_pvf(
87+
PvfPrepData::from_code(
88+
code.into(),
89+
executor_params,
90+
TEST_PREPARATION_TIMEOUT,
91+
PrepareJobKind::Prechecking,
92+
),
93+
result_tx,
94+
)
95+
.await
96+
.unwrap();
97+
result_rx.await.unwrap()
98+
}
99+
73100
async fn validate_candidate(
74101
&self,
75102
code: &[u8],
@@ -321,3 +348,19 @@ async fn deleting_prepared_artifact_does_not_dispute() {
321348
r => panic!("{:?}", r),
322349
}
323350
}
351+
352+
// With one worker, run multiple preparation jobs serially. They should not conflict.
353+
#[tokio::test]
354+
async fn prepare_can_run_serially() {
355+
let host = TestHost::new_with_config(|cfg| {
356+
cfg.prepare_workers_hard_max_num = 1;
357+
});
358+
359+
let _stats = host
360+
.precheck_pvf(::adder::wasm_binary_unwrap(), Default::default())
361+
.await
362+
.unwrap();
363+
364+
// Prepare a different wasm blob to prevent skipping work.
365+
let _stats = host.precheck_pvf(halt::wasm_binary_unwrap(), Default::default()).await.unwrap();
366+
}

0 commit comments

Comments
 (0)