Download codex-rs/diagnostics/src/tests.rs from SaylorTwift/codex: direct link, hf CLI and curl.
- Browser
- Download file 1.69 kB
-
https://huggingface.co/SaylorTwift/codex/resolve/main/codex-rs/diagnostics/src/tests.rs
- Command line
-
hf download hf://SaylorTwift/codex/codex-rs/diagnostics/src/tests.rs
-
curl -L -o tests.rs https://huggingface.co/SaylorTwift/codex/resolve/main/codex-rs/diagnostics/src/tests.rs
1.69 kB
| use super::Gauge; | |
| use super::snapshot; | |
| use pretty_assertions::assert_eq; | |
| static GUARD_GAUGE: Gauge = Gauge::new("diagnostics.tests.guard"); | |
| static REGISTERED_GAUGE: Gauge = Gauge::new("diagnostics.tests.registered"); | |
| fn gauge_guards_follow_the_measured_lifetime() { | |
| let first = GUARD_GAUGE.track(); | |
| let second = GUARD_GAUGE.track(); | |
| let value = || { | |
| snapshot() | |
| .gauges | |
| .into_iter() | |
| .find(|gauge| gauge.name == "diagnostics.tests.guard") | |
| .expect("used gauge should be registered") | |
| .value | |
| }; | |
| assert_eq!(value(), 2); | |
| drop(first); | |
| assert_eq!(value(), 1); | |
| drop(second); | |
| assert_eq!(value(), 0); | |
| } | |
| fn snapshot_includes_process_memory_and_registers_gauges_once() { | |
| REGISTERED_GAUGE.increment(); | |
| REGISTERED_GAUGE.increment(); | |
| let diagnostics = snapshot(); | |
| let registered = diagnostics | |
| .gauges | |
| .iter() | |
| .filter(|gauge| gauge.name == "diagnostics.tests.registered") | |
| .collect::<Vec<_>>(); | |
| assert_eq!(diagnostics.process.id, std::process::id()); | |
| assert_eq!(registered.len(), 1); | |
| assert_eq!(registered[0].value, 2); | |
| assert!( | |
| diagnostics | |
| .process | |
| .resident_memory_bytes | |
| .is_some_and(|bytes| bytes > 0) | |
| ); | |
| assert!( | |
| diagnostics | |
| .process | |
| .physical_footprint_bytes | |
| .is_some_and(|bytes| bytes > 0) | |
| ); | |
| assert_eq!(diagnostics.process.physical_footprint_bytes, None); | |
| } | |