-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #121 from moka-rs/gh119-quanta
Make Quanta crate optional (but enabled by default)
- Loading branch information
Showing
15 changed files
with
197 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
name: CI (Quanta disabled) | ||
|
||
on: | ||
push: | ||
paths-ignore: | ||
- '.devcontainer/**' | ||
- '.gitpod.yml' | ||
- '.vscode/**' | ||
pull_request: | ||
paths-ignore: | ||
- '.devcontainer/**' | ||
- '.gitpod.yml' | ||
- '.vscode/**' | ||
schedule: | ||
# Run against the last commit on the default branch on Friday at 8pm (UTC?) | ||
- cron: '0 20 * * 5' | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
rust: | ||
- stable | ||
- beta | ||
- 1.51.0 # MSRV | ||
- nightly # For checking minimum version dependencies. | ||
|
||
steps: | ||
- name: Checkout Moka | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install Rust toolchain | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: ${{ matrix.rust }} | ||
override: true | ||
components: rustfmt, clippy | ||
|
||
- uses: Swatinem/rust-cache@v1 | ||
|
||
- name: cargo clean | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: clean | ||
|
||
- name: Downgrade dependencies to minimal versions (Nightly only) | ||
uses: actions-rs/cargo@v1 | ||
if: ${{ matrix.rust == 'nightly' }} | ||
with: | ||
command: update | ||
args: -Z minimal-versions | ||
|
||
- name: Pin some dependencies to specific versions (MSRV only) | ||
if: ${{ matrix.rust == '1.51.0' }} | ||
# Avoid hashbrown >= v0.12, which requires Rust 2021 edition. | ||
run: | | ||
cargo update -p dashmap --precise 5.2.0 | ||
cargo update -p hashbrown --precise 0.11.2 | ||
- name: Build (no quanta feature) | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: build | ||
args: --no-default-features --features atomic64 | ||
|
||
- name: Run tests (release, no quanta feature) | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: test | ||
args: --release --no-default-features --features atomic64 | ||
|
||
- name: Run tests (future feature, but no quanta feature) | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: test | ||
args: --no-default-features --features 'future, atomic64' | ||
|
||
- name: Run tests (dash feature, but no quanta feature) | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: test | ||
args: --no-default-features --features 'dash, atomic64' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/common/atomic_time_compat.rs → src/common/time/atomic_time_compat.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
use super::time::Instant; | ||
use super::Instant; | ||
|
||
use parking_lot::RwLock; | ||
|
||
pub(crate) struct AtomicInstant { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use std::{sync::Arc, time::Instant as StdInstant}; | ||
|
||
#[cfg(test)] | ||
use std::time::Duration; | ||
|
||
use parking_lot::RwLock; | ||
|
||
pub(crate) type Instant = StdInstant; | ||
|
||
pub(crate) struct Clock { | ||
mock: Option<Arc<Mock>>, | ||
} | ||
|
||
impl Clock { | ||
#[cfg(test)] | ||
pub(crate) fn mock() -> (Clock, Arc<Mock>) { | ||
let mock = Arc::new(Mock::default()); | ||
let clock = Clock { | ||
mock: Some(Arc::clone(&mock)), | ||
}; | ||
(clock, mock) | ||
} | ||
|
||
pub(crate) fn now(&self) -> Instant { | ||
if let Some(mock) = &self.mock { | ||
*mock.now.read() | ||
} else { | ||
StdInstant::now() | ||
} | ||
} | ||
} | ||
|
||
pub(crate) struct Mock { | ||
now: RwLock<Instant>, | ||
} | ||
|
||
impl Default for Mock { | ||
fn default() -> Self { | ||
Self { | ||
now: RwLock::new(StdInstant::now()), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
impl Mock { | ||
pub(crate) fn increment(&self, amount: Duration) { | ||
*self.now.write() += amount; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub(crate) type Clock = quanta::Clock; | ||
pub(crate) type Instant = quanta::Instant; | ||
|
||
#[cfg(test)] | ||
pub(crate) type Mock = quanta::Mock; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters