Skip to content

Commit

Permalink
feat: allow running more than one runtime at a time
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Feb 20, 2024
1 parent 47010a4 commit 8e2a988
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions csaf/src/verification/check/csaf_validator_lib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,15 @@ pub enum Profile {
}

pub struct CsafValidatorLib {
runtime: Arc<Mutex<Option<InnerCheck>>>,
runtime: Arc<Mutex<Vec<InnerCheck>>>,
validations: Vec<ValidationSet>,
timeout: Option<Duration>,
ignore: HashSet<String>,
}

impl CsafValidatorLib {
pub fn new(profile: Profile) -> Self {
let runtime = Arc::new(Mutex::new(None));
let runtime = Arc::new(Mutex::new(vec![]));

let validations = match profile {
Profile::Schema => vec![ValidationSet::Schema],
Expand Down Expand Up @@ -275,13 +275,11 @@ impl CsafValidatorLib {
#[async_trait(?Send)]
impl Check for CsafValidatorLib {
async fn check(&self, csaf: &Csaf) -> anyhow::Result<Vec<CheckError>> {
let mut inner_lock = self.runtime.lock().await;

let inner = match &mut *inner_lock {
Some(inner) => inner,
None => {
let new = InnerCheck::new().await?;
inner_lock.get_or_insert(new)
let mut inner = {
let mut inner_lock = self.runtime.lock().await;
match inner_lock.pop() {
Some(inner) => inner,
None => InnerCheck::new().await?,
}
};

Expand All @@ -292,11 +290,12 @@ impl Check for CsafValidatorLib {
log::trace!("Result: {test_result:?}");

let Some(test_result) = test_result else {
// clear instance, and return timeout
inner_lock.take();
return Ok(vec!["check timed out".into()]);
};

// not timed out, we can re-use it
self.runtime.lock().await.push(inner);

let mut result = vec![];

for entry in test_result.tests {
Expand Down

0 comments on commit 8e2a988

Please sign in to comment.