From 71deaa3c7c029644b76a2d4b462b558a7faa9340 Mon Sep 17 00:00:00 2001 From: Nick Lanham Date: Fri, 13 Dec 2024 13:28:45 -0800 Subject: [PATCH] don't use std abs_diff, put it in test_utils instead, run tests with msrv in action (#596) ## What changes are proposed in this pull request? - create an abs_diff function in test_utils (same code as in std) - use that in the two places we wanted it instead - also add a workflow to make sure that we can always compile against msrv ## How was this change tested? - Existing tests pass - New workflow passes --- .github/workflows/build.yml | 28 +++++++++++++++++++++++++ kernel/src/engine/default/filesystem.rs | 4 ++-- kernel/src/engine/sync/fs_client.rs | 4 +++- test-utils/src/lib.rs | 10 +++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 746a05e37..270dd3c45 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,6 +41,34 @@ jobs: cargo msrv --path derive-macros/ verify --all-features cargo msrv --path ffi/ verify --all-features cargo msrv --path ffi-proc-macros/ verify --all-features + msrv-run-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install minimal stable and cargo msrv + uses: actions-rs/toolchain@v1 + with: + profile: default + toolchain: stable + override: true + - uses: Swatinem/rust-cache@v2 + - name: Install cargo-msrv + shell: bash + run: | + cargo install cargo-msrv --locked + - name: Get rust-version from Cargo.toml + id: rust-version + run: echo "RUST_VERSION=$(cargo msrv show --path kernel/ --output-format minimal)" >> $GITHUB_ENV + - name: Install specified rust version + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ env.RUST_VERSION }} + profile: minimal + - name: run tests + run: | + pushd kernel + echo "Testing with $(cargo msrv show --output-format minimal)" + cargo +$(cargo msrv show --output-format minimal) test docs: runs-on: ubuntu-latest env: diff --git a/kernel/src/engine/default/filesystem.rs b/kernel/src/engine/default/filesystem.rs index 36b110774..5606a28d0 100644 --- a/kernel/src/engine/default/filesystem.rs +++ b/kernel/src/engine/default/filesystem.rs @@ -160,7 +160,7 @@ mod tests { use object_store::memory::InMemory; use object_store::{local::LocalFileSystem, ObjectStore}; - use test_utils::delta_path_for_version; + use test_utils::{abs_diff, delta_path_for_version}; use crate::engine::default::executor::tokio::TokioBackgroundExecutor; use crate::engine::default::DefaultEngine; @@ -241,7 +241,7 @@ mod tests { assert!(!files.is_empty()); for meta in files.into_iter() { let meta_time = Duration::from_millis(meta.last_modified.try_into().unwrap()); - assert!(meta_time.abs_diff(begin_time) < Duration::from_secs(10)); + assert!(abs_diff(meta_time, begin_time) < Duration::from_secs(10)); } } #[tokio::test] diff --git a/kernel/src/engine/sync/fs_client.rs b/kernel/src/engine/sync/fs_client.rs index a5c889da5..9577b1499 100644 --- a/kernel/src/engine/sync/fs_client.rs +++ b/kernel/src/engine/sync/fs_client.rs @@ -84,6 +84,8 @@ mod tests { use itertools::Itertools; use url::Url; + use test_utils::abs_diff; + use super::SyncFilesystemClient; use crate::FileSystemClient; @@ -111,7 +113,7 @@ mod tests { assert!(!files.is_empty()); for meta in files.iter() { let meta_time = Duration::from_millis(meta.last_modified.try_into()?); - assert!(meta_time.abs_diff(begin_time) < Duration::from_secs(10)); + assert!(abs_diff(meta_time, begin_time) < Duration::from_secs(10)); } Ok(()) } diff --git a/test-utils/src/lib.rs b/test-utils/src/lib.rs index e43e8481c..2605bea56 100644 --- a/test-utils/src/lib.rs +++ b/test-utils/src/lib.rs @@ -106,3 +106,13 @@ pub fn into_record_batch(engine_data: Box) -> RecordBatch { .unwrap() .into() } + +/// We implement abs_diff here so we don't have to bump our msrv. +/// TODO: Remove and use std version when msrv >= 1.81.0 +pub fn abs_diff(self_dur: std::time::Duration, other: std::time::Duration) -> std::time::Duration { + if let Some(res) = self_dur.checked_sub(other) { + res + } else { + other.checked_sub(self_dur).unwrap() + } +}