Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 0e7dad5

Browse files
committed
pvf: Add checks for result sender when retrying preparation in tests
1 parent c80124e commit 0e7dad5

1 file changed

Lines changed: 65 additions & 13 deletions

File tree

node/core/pvf/src/host.rs

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,13 @@ mod tests {
931931
ValidationHost { to_host_tx }
932932
}
933933

934+
async fn poll_and_recv_result<T>(&mut self, result_rx: oneshot::Receiver<T>) -> T
935+
where
936+
T: Send,
937+
{
938+
run_until(&mut self.run, async { result_rx.await.unwrap() }.boxed()).await
939+
}
940+
934941
async fn poll_and_recv_to_prepare_queue(&mut self) -> prepare::ToQueue {
935942
let to_prepare_queue_rx = &mut self.to_prepare_queue_rx;
936943
run_until(&mut self.run, async { to_prepare_queue_rx.next().await.unwrap() }.boxed())
@@ -991,7 +998,7 @@ mod tests {
991998
futures::select! {
992999
_ = Delay::new(Duration::from_millis(500)).fuse() => (),
9931000
msg = to_sweeper_rx.next().fuse() => {
994-
panic!("the sweeper supposed to be empty, but received: {:?}", msg)
1001+
panic!("the sweeper is supposed to be empty, but received: {:?}", msg)
9951002
}
9961003
}
9971004
}
@@ -1311,12 +1318,12 @@ mod tests {
13111318
// Test that multiple prechecking requests do not trigger preparation retries if the first one
13121319
// failed.
13131320
#[tokio::test]
1314-
async fn test_precheck_prepare_retry() {
1321+
async fn test_precheck_prepare_no_retry() {
13151322
let mut test = Builder::default().build();
13161323
let mut host = test.host_handle();
13171324

13181325
// Submit a precheck request that fails.
1319-
let (result_tx, _result_rx) = oneshot::channel();
1326+
let (result_tx, result_rx) = oneshot::channel();
13201327
host.precheck_pvf(Pvf::from_discriminator(1), result_tx).await.unwrap();
13211328

13221329
// The queue received the prepare request.
@@ -1333,22 +1340,34 @@ mod tests {
13331340
.await
13341341
.unwrap();
13351342

1343+
// The result should contain the error.
1344+
let result = test.poll_and_recv_result(result_rx).await;
1345+
assert_matches!(result, Err(PrepareError::TimedOut));
1346+
13361347
// Submit another precheck request.
1337-
let (result_tx_2, _result_rx_2) = oneshot::channel();
1348+
let (result_tx_2, result_rx_2) = oneshot::channel();
13381349
host.precheck_pvf(Pvf::from_discriminator(1), result_tx_2).await.unwrap();
13391350

13401351
// Assert the prepare queue is empty.
13411352
test.poll_ensure_to_prepare_queue_is_empty().await;
13421353

1354+
// The result should contain the original error.
1355+
let result = test.poll_and_recv_result(result_rx_2).await;
1356+
assert_matches!(result, Err(PrepareError::TimedOut));
1357+
13431358
// Pause for enough time to reset the cooldown for this failed prepare request.
13441359
futures_timer::Delay::new(PREPARE_FAILURE_COOLDOWN).await;
13451360

13461361
// Submit another precheck request.
1347-
let (result_tx_3, _result_rx_3) = oneshot::channel();
1362+
let (result_tx_3, result_rx_3) = oneshot::channel();
13481363
host.precheck_pvf(Pvf::from_discriminator(1), result_tx_3).await.unwrap();
13491364

13501365
// Assert the prepare queue is empty - we do not retry for precheck requests.
13511366
test.poll_ensure_to_prepare_queue_is_empty().await;
1367+
1368+
// The result should still contain the original error.
1369+
let result = test.poll_and_recv_result(result_rx_3).await;
1370+
assert_matches!(result, Err(PrepareError::TimedOut));
13521371
}
13531372

13541373
// Test that multiple execution requests trigger preparation retries if the first one failed due
@@ -1359,7 +1378,7 @@ mod tests {
13591378
let mut host = test.host_handle();
13601379

13611380
// Submit a execute request that fails.
1362-
let (result_tx, _result_rx) = oneshot::channel();
1381+
let (result_tx, result_rx) = oneshot::channel();
13631382
host.execute_pvf(
13641383
Pvf::from_discriminator(1),
13651384
TEST_EXECUTION_TIMEOUT,
@@ -1384,8 +1403,12 @@ mod tests {
13841403
.await
13851404
.unwrap();
13861405

1387-
// Submit another execute request.
1388-
let (result_tx_2, _result_rx_2) = oneshot::channel();
1406+
// The result should contain the error.
1407+
let result = test.poll_and_recv_result(result_rx).await;
1408+
assert_matches!(result, Err(ValidationError::InternalError(_)));
1409+
1410+
// Submit another execute request. We shouldn't try to prepare again, yet.
1411+
let (result_tx_2, result_rx_2) = oneshot::channel();
13891412
host.execute_pvf(
13901413
Pvf::from_discriminator(1),
13911414
TEST_EXECUTION_TIMEOUT,
@@ -1399,11 +1422,15 @@ mod tests {
13991422
// Assert the prepare queue is empty.
14001423
test.poll_ensure_to_prepare_queue_is_empty().await;
14011424

1425+
// The result should contain the original error.
1426+
let result = test.poll_and_recv_result(result_rx_2).await;
1427+
assert_matches!(result, Err(ValidationError::InternalError(_)));
1428+
14021429
// Pause for enough time to reset the cooldown for this failed prepare request.
14031430
futures_timer::Delay::new(PREPARE_FAILURE_COOLDOWN).await;
14041431

14051432
// Submit another execute request.
1406-
let (result_tx_3, _result_rx_3) = oneshot::channel();
1433+
let (result_tx_3, result_rx_3) = oneshot::channel();
14071434
host.execute_pvf(
14081435
Pvf::from_discriminator(1),
14091436
TEST_EXECUTION_TIMEOUT,
@@ -1419,6 +1446,10 @@ mod tests {
14191446
test.poll_and_recv_to_prepare_queue().await,
14201447
prepare::ToQueue::Enqueue { .. }
14211448
);
1449+
1450+
// Preparation should have been retried and succeeded this time.
1451+
let result = test.poll_and_recv_result(result_rx_3).await;
1452+
assert_matches!(result, Err(ValidationError::InternalError(_)));
14221453
}
14231454

14241455
// Test that multiple execution requests don't trigger preparation retries if the first one
@@ -1428,8 +1459,8 @@ mod tests {
14281459
let mut test = Builder::default().build();
14291460
let mut host = test.host_handle();
14301461

1431-
// Submit a execute request that fails.
1432-
let (result_tx, _result_rx) = oneshot::channel();
1462+
// Submit an execute request that fails.
1463+
let (result_tx, result_rx) = oneshot::channel();
14331464
host.execute_pvf(
14341465
Pvf::from_discriminator(1),
14351466
TEST_EXECUTION_TIMEOUT,
@@ -1454,8 +1485,15 @@ mod tests {
14541485
.await
14551486
.unwrap();
14561487

1488+
// The result should contain the error.
1489+
let result = test.poll_and_recv_result(result_rx).await;
1490+
assert_matches!(
1491+
result,
1492+
Err(ValidationError::InvalidCandidate(InvalidCandidate::PrepareError(_)))
1493+
);
1494+
14571495
// Submit another execute request.
1458-
let (result_tx_2, _result_rx_2) = oneshot::channel();
1496+
let (result_tx_2, result_rx_2) = oneshot::channel();
14591497
host.execute_pvf(
14601498
Pvf::from_discriminator(1),
14611499
TEST_EXECUTION_TIMEOUT,
@@ -1469,11 +1507,18 @@ mod tests {
14691507
// Assert the prepare queue is empty.
14701508
test.poll_ensure_to_prepare_queue_is_empty().await;
14711509

1510+
// The result should contain the original error.
1511+
let result = test.poll_and_recv_result(result_rx_2).await;
1512+
assert_matches!(
1513+
result,
1514+
Err(ValidationError::InvalidCandidate(InvalidCandidate::PrepareError(_)))
1515+
);
1516+
14721517
// Pause for enough time to reset the cooldown for this failed prepare request.
14731518
futures_timer::Delay::new(PREPARE_FAILURE_COOLDOWN).await;
14741519

14751520
// Submit another execute request.
1476-
let (result_tx_3, _result_rx_3) = oneshot::channel();
1521+
let (result_tx_3, result_rx_3) = oneshot::channel();
14771522
host.execute_pvf(
14781523
Pvf::from_discriminator(1),
14791524
TEST_EXECUTION_TIMEOUT,
@@ -1486,6 +1531,13 @@ mod tests {
14861531

14871532
// Assert the prepare queue is empty - we do not retry for prevalidation errors.
14881533
test.poll_ensure_to_prepare_queue_is_empty().await;
1534+
1535+
// The result should still contain the original error.
1536+
let result = test.poll_and_recv_result(result_rx_3).await;
1537+
assert_matches!(
1538+
result,
1539+
Err(ValidationError::InvalidCandidate(InvalidCandidate::PrepareError(_)))
1540+
);
14891541
}
14901542

14911543
// Test that multiple heads-up requests trigger preparation retries if the first one failed.

0 commit comments

Comments
 (0)