Skip to content

Commit

Permalink
[eclipse-iceoryx#231] Add test interface to file lock
Browse files Browse the repository at this point in the history
  • Loading branch information
elfenpiff committed Jun 13, 2024
1 parent 4eada9e commit f25debb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
17 changes: 12 additions & 5 deletions iceoryx2-cal/src/monitoring/file_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use iceoryx2_bb_posix::{
ProcessCleaner, ProcessCleanerCreateError, ProcessGuard, ProcessGuardCreateError,
ProcessMonitor, ProcessMonitorCreateError, ProcessMonitorStateError, ProcessState,
},
testing::__internal_process_guard_staged_death,
};
use iceoryx2_bb_system_types::{file_name::FileName, path::Path};

Expand All @@ -31,8 +32,8 @@ use crate::{
};

use super::{
Monitoring, MonitoringBuilder, MonitoringCleaner, MonitoringCreateTokenError,
MonitoringMonitor, MonitoringStateError, MonitoringToken,
testing::__InternalMonitoringTokenTestable, Monitoring, MonitoringBuilder, MonitoringCleaner,
MonitoringCreateTokenError, MonitoringMonitor, MonitoringStateError, MonitoringToken,
};

#[derive(Debug)]
Expand Down Expand Up @@ -141,7 +142,7 @@ impl MonitoringCleaner for Cleaner {}

#[derive(Debug)]
pub struct Token {
_guard: ProcessGuard,
guard: ProcessGuard,
name: FileName,
}

Expand All @@ -153,6 +154,12 @@ impl NamedConcept for Token {

impl MonitoringToken for Token {}

impl __InternalMonitoringTokenTestable for Token {
fn staged_death(self) {
__internal_process_guard_staged_death(self.guard);
}
}

#[derive(Debug)]
pub struct Monitor {
monitor: ProcessMonitor,
Expand Down Expand Up @@ -215,8 +222,8 @@ impl MonitoringBuilder<FileLockMonitoring> for Builder {
let msg = "Unable to create FileLockMonitoring token";
let process_state_path = self.config.path_for(&self.name);
match ProcessGuard::new(&process_state_path) {
Ok(_guard) => Ok(Token {
_guard,
Ok(guard) => Ok(Token {
guard,
name: self.name,
}),
Err(ProcessGuardCreateError::InsufficientPermissions) => {
Expand Down
2 changes: 2 additions & 0 deletions iceoryx2-cal/src/monitoring/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ pub use crate::{

pub mod file_lock;
pub mod process_local;
#[doc(hidden)]
pub mod testing;

/// Represents the state of a monitored process.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down
15 changes: 15 additions & 0 deletions iceoryx2-cal/src/monitoring/testing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2024 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Apache Software License 2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
// which is available at https://opensource.org/licenses/MIT.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT

pub trait __InternalMonitoringTokenTestable {
fn staged_death(self);
}

0 comments on commit f25debb

Please sign in to comment.