Skip to content

Commit

Permalink
Merge version peek and reset
Browse files Browse the repository at this point in the history
Implementing peeking

Add more peek functions

Fix failing tests

Implemented peek

Fix n key peek function

Added peek tests for n advances

Implemented reset

Added reset test for dashmap

stable formatting

fix failing no)_std tests

Fix formatting

Clippy lints

Add test for peek

Add tests

Add tests

Add dashmap tests

assert coverage test

Address coverage

formatting

Move reset from unit to bool return type

Change to nested results

Format code

direct tests codecov

Codecov wip

Improve codecov and tests

Codecov wip

formatting

Codecov wip

formatting

Improve runtime

Add rand dep

Test peek

formatting

fix compiling

fix std lib

Improve tests

formattings

non std import removed

Improve reset tests

Adressed comments

Added tests

Call measure and peek in collision

Added peek test for codecov

Include test for M1 since now fixed

Remove clock default impl

Add coverage code

Silence clippy

Increase coverage

Clippy fixes

Trigger pipeline

Rebase upstream

Add race condition test

formatting

limit test to std

Trigger pipeline

Retrigger pipeline

trigger compare_exchange_weak failure

Improve comment

Add comments

Reduce sleep

Add tests for clone and default

Add clone and debug

formatting

Fix debug test
  • Loading branch information
jmfrank63 committed Jan 28, 2024
1 parent f0cb09c commit ae82c95
Show file tree
Hide file tree
Showing 20 changed files with 1,171 additions and 102 deletions.
2 changes: 2 additions & 0 deletions governor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ libc = "0.2.70"
futures = "0.3.5"
proptest = "1.0.0"
all_asserts = "2.2.0"
rand = "0.8.0"
num_cpus = "1.13.0"

[features]
default = ["std", "dashmap", "jitter", "quanta"]
Expand Down
2 changes: 1 addition & 1 deletion governor/benches/realtime_clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn bench_all(c: &mut Criterion) {
macro_rules! with_realtime_clocks {
{($name:expr, $group:ident) |$b:pat, $clock:pat| $closure:block} => {
{
let clock = clock::MonotonicClock::default();
let clock = clock::MonotonicClock;
$group.bench_with_input(BenchmarkId::new($name, "MonotonicClock"), &clock, |$b, $clock| $closure);
}
{
Expand Down
13 changes: 10 additions & 3 deletions governor/src/clock/quanta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,23 @@ mod test {
#[test]
fn quanta_upkeep_impls_coverage() {
let one_ns = Nanos::new(1);
// let _c1 =
// QuantaUpkeepClock::from_builder(quanta::Upkeep::new(Duration::from_secs(1))).unwrap();
let c = QuantaUpkeepClock::from_interval(Duration::from_secs(1)).unwrap();
let now = c.now();
let n = c;
let now = n.now();
assert_ne!(now + one_ns, now);
assert_eq!(one_ns, Reference::duration_since(&(now + one_ns), now));
assert_eq!(Nanos::new(0), Reference::duration_since(&now, now + one_ns));
assert_eq!(
Reference::saturating_sub(&(now + Duration::from_nanos(1).into()), one_ns),
now
);

// Test the Clone implementation
let c_clone = n.clone();
let now_clone = c_clone.now();
assert_eq!(now, now_clone);
// Check that the debug string is not empty
let debug_str = format!("{:?}", c_clone);
assert!(!debug_str.is_empty());
}
}
38 changes: 18 additions & 20 deletions governor/src/clock/with_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,33 +96,31 @@ impl ReasonablyRealtime for SystemClock {}
/// Some tests to ensure that the code above gets exercised. We don't
/// rely on them in tests (being nastily tainted by realism), so we
/// have to get creative.
#[allow(clippy::default_constructed_unit_structs)]
#[cfg(test)]
mod test {
use super::*;
use crate::clock::{Clock, Reference, SystemClock};
use crate::nanos::Nanos;
use std::time::Duration;

cfg_if::cfg_if! {
// This test is broken on macOS on M1 machines, due to
// https://github.com/rust-lang/rust/issues/91417:
if #[cfg(not(all(target_arch = "aarch64", target_os = "macos")))] {
use crate::clock::MonotonicClock;
#[test]
fn instant_impls_coverage() {
let one_ns = Nanos::new(1);
let c = MonotonicClock::default();
let now = c.now();
let ns_dur = Duration::from(one_ns);
assert_ne!(now + ns_dur, now, "{:?} + {:?}", ns_dur, now);
assert_eq!(one_ns, Reference::duration_since(&(now + one_ns), now));
assert_eq!(Nanos::new(0), Reference::duration_since(&now, now + one_ns));
assert_eq!(
Reference::saturating_sub(&(now + Duration::from_nanos(1)), one_ns),
now
);
}
}
use crate::clock::MonotonicClock;
#[test]
fn instant_impls_coverage() {
let one_ns = Nanos::new(1);

let c = MonotonicClock::default();
format!("{:?}", c);
let n = c;
let now = n.now();
let ns_dur = Duration::from(one_ns);
assert_ne!(now + ns_dur, now, "{:?} + {:?}", ns_dur, now);
assert_eq!(one_ns, Reference::duration_since(&(now + one_ns), now));
assert_eq!(Nanos::new(0), Reference::duration_since(&now, now + one_ns));
assert_eq!(
Reference::saturating_sub(&(now + Duration::from_nanos(1)), one_ns),
now
);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions governor/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ mod test {
#[test]
fn coverage() {
let display_output = format!("{}", InsufficientCapacity(3));
assert!(display_output.contains("3"));
assert!(display_output.contains('3'));
let debug_output = format!("{:?}", InsufficientCapacity(3));
assert!(debug_output.contains("3"));
assert!(debug_output.contains('3'));
assert_eq!(InsufficientCapacity(3), InsufficientCapacity(3));
}
}
Loading

0 comments on commit ae82c95

Please sign in to comment.