running_process_platform_internal/platform/
resources.rs1pub use crate::{
13 resources_fd_exhaustion_error as fd_exhaustion_error,
14 resources_inode_capacity as inode_capacity,
15 resources_signals_fd_exhaustion as signals_fd_exhaustion,
16 resources_signals_storage_exhaustion as signals_storage_exhaustion,
17 resources_storage_exhaustion_error as storage_exhaustion_error,
18};
19
20#[derive(Clone, Copy, Debug, PartialEq, Eq)]
25pub struct InodeCapacity {
26 pub total: u64,
28 pub free: u64,
30}
31
32#[cfg(test)]
33mod tests {
34 use std::io;
35
36 use super::*;
37
38 #[test]
41 fn this_hosts_exhaustion_errors_are_recognised() {
42 assert!(
43 signals_fd_exhaustion(&fd_exhaustion_error()),
44 "a descriptor-exhaustion error must be recognised as one"
45 );
46 assert!(
47 signals_storage_exhaustion(&storage_exhaustion_error()),
48 "a storage-exhaustion error must be recognised as one"
49 );
50 }
51
52 #[test]
55 fn the_two_exhaustion_conditions_stay_distinct() {
56 assert!(!signals_storage_exhaustion(&fd_exhaustion_error()));
57 assert!(!signals_fd_exhaustion(&storage_exhaustion_error()));
58 }
59
60 #[test]
63 fn an_error_without_an_os_code_signals_nothing() {
64 let synthetic = io::Error::other("no operating system said this");
65 assert!(!signals_fd_exhaustion(&synthetic));
66 assert!(!signals_storage_exhaustion(&synthetic));
67 }
68
69 #[test]
71 fn an_unrelated_os_error_signals_nothing() {
72 let denied = io::Error::new(io::ErrorKind::PermissionDenied, "denied");
73 assert!(!signals_fd_exhaustion(&denied));
74 assert!(!signals_storage_exhaustion(&denied));
75 }
76
77 #[test]
80 fn probing_an_existing_directory_answers_coherently() {
81 let probed = inode_capacity(&std::env::temp_dir()).expect("probing temp dir must succeed");
82 if let Some(capacity) = probed {
83 assert!(capacity.total > 0, "a reported table is never empty");
84 assert!(
85 capacity.free <= capacity.total,
86 "free inodes cannot exceed the table"
87 );
88 }
89 }
90}