|
18 | 18 | use assert_matches::assert_matches;
|
19 | 19 | use parity_scale_codec::Encode as _;
|
20 | 20 | 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, |
23 | 23 | };
|
24 | 24 | use polkadot_parachain_primitives::primitives::{BlockData, ValidationParams, ValidationResult};
|
25 | 25 | use polkadot_primitives::ExecutorParams;
|
@@ -70,6 +70,33 @@ impl TestHost {
|
70 | 70 | Self { cache_dir, host: Mutex::new(host) }
|
71 | 71 | }
|
72 | 72 |
|
| 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 | + |
73 | 100 | async fn validate_candidate(
|
74 | 101 | &self,
|
75 | 102 | code: &[u8],
|
@@ -321,3 +348,19 @@ async fn deleting_prepared_artifact_does_not_dispute() {
|
321 | 348 | r => panic!("{:?}", r),
|
322 | 349 | }
|
323 | 350 | }
|
| 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