|
| 1 | +use super::context::{SignerTestContext, SignerTestState}; |
| 2 | +use crate::tests::signer::v0::MultipleMinerTest; |
| 3 | +use madhouse::{Command, CommandWrapper}; |
| 4 | +use proptest::prelude::{Just, Strategy}; |
| 5 | +use std::sync::{Arc, Mutex}; |
| 6 | + |
| 7 | +pub struct ShutdownMinersCommand { |
| 8 | + miners: Arc<Mutex<MultipleMinerTest>>, |
| 9 | +} |
| 10 | + |
| 11 | +impl ShutdownMinersCommand { |
| 12 | + pub fn new(miners: Arc<Mutex<MultipleMinerTest>>) -> Self { |
| 13 | + Self { miners } |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +impl Command<SignerTestState, SignerTestContext> for ShutdownMinersCommand { |
| 18 | + fn check(&self, _state: &SignerTestState) -> bool { |
| 19 | + println!("Checking: Shutting down miners. Result: {:?}", true); |
| 20 | + true |
| 21 | + } |
| 22 | + |
| 23 | + fn apply(&self, _state: &mut SignerTestState) { |
| 24 | + println!("Applying: Shutting down miners"); |
| 25 | + |
| 26 | + if let Ok(miners_arc) = Arc::try_unwrap(self.miners.clone()) { |
| 27 | + if let Ok(miners) = miners_arc.into_inner() { |
| 28 | + miners.shutdown(); |
| 29 | + } |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + fn label(&self) -> String { |
| 34 | + "SHUTDOWN_MINERS".to_string() |
| 35 | + } |
| 36 | + |
| 37 | + fn build( |
| 38 | + ctx: Arc<SignerTestContext>, |
| 39 | + ) -> impl Strategy<Value = CommandWrapper<SignerTestState, SignerTestContext>> { |
| 40 | + Just(CommandWrapper::new(ShutdownMinersCommand::new( |
| 41 | + ctx.miners.clone(), |
| 42 | + ))) |
| 43 | + } |
| 44 | +} |
0 commit comments