Skip to content

Commit

Permalink
Try #35:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Sep 26, 2020
2 parents d5d1a23 + fde2d76 commit 2da4a65
Show file tree
Hide file tree
Showing 17 changed files with 388 additions and 170 deletions.
76 changes: 76 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version: "2.1"
orbs:
browser-tools: circleci/[email protected]

executors: {
"beta": {
Expand Down Expand Up @@ -37,6 +39,29 @@ commands:
- run:
name: Test
command: cargo test --verbose --all
wasm_pack_install:
description: "Installs `wasm-pack`"
steps:
# We need to install a custom build of wasm-pack as it doesn't pass through parameters to cargo correctly:
# <https://github.com/rustwasm/wasm-pack/pull/851>
# - run:
# name: "Install wasm-pack"
# command: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- run:
name: "Install wasm-pack"
command: cargo install --git https://github.com/azriel91/wasm-pack.git --branch bugfix/698/build-tests-with-passthrough-args --force
- run:
name: "Print wasm-pack version"
command: "wasm-pack --version"
wasm_pack_test:
description: "Runs WASM Tests"
parameters:
browser:
type: string
steps:
- run:
name: "Test With Browser (<< parameters.browser >>)"
command: wasm-pack test --headless --<< parameters.browser >> -- --no-default-features --features "std wasm-bindgen"

jobs:
test:
Expand All @@ -52,6 +77,23 @@ jobs:
- checkout
- cargo_test

wasm_test:
parameters:
version:
type: executor
version_name:
type: string
browser:
type: string
executor: << parameters.version >>
environment:
CI_RUST_VERSION: << parameters.version_name >>
steps:
- browser-tools/install-browser-tools
- checkout
- wasm_pack_install
- wasm_pack_test: { browser: << parameters.browser >> }

rustfmt:
parameters:
version:
Expand Down Expand Up @@ -153,6 +195,40 @@ workflows:
"/^v\\d+\\.\\d+\\.\\d+.*$/"
]
}
}
- wasm_test:
name: wasm_test-chrome
version: stable
version_name: stable
browser: chrome
filters: {
"branches": {
"ignore": [
"/.*\\.tmp/"
]
},
"tags": {
"only": [
"/^v\\d+\\.\\d+\\.\\d+.*$/"
]
}
}
- wasm_test:
name: wasm_test-firefox
version: stable
version_name: stable
browser: firefox
filters: {
"branches": {
"ignore": [
"/.*\\.tmp/"
]
},
"tags": {
"only": [
"/^v\\d+\\.\\d+\\.\\d+.*$/"
]
}
}
- rustfmt:
version: stable
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

## [Unreleased] - ReleaseDate

### Added

* Support for the `wasm32-unknown-unknown` target. Default features have to be
disabled so that native dependencies are not built, and `Jitter` is not
available.

### Contributors

* [@azriel91](https://github.com/azriel91)

## [[0.3.1](https://docs.rs/governor/0.3.1/governor/)] - 2020-07-26

### Added
Expand Down
15 changes: 13 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ keywords = ["rate-limiting", "rate-limit", "no_std", "gcra"]
# We use criterion, don't infer benchmark files.
autobenches = false

[lib]
crate-type = ["cdylib", "rlib"]

[package.metadata.template_ci.bench]
run = true
version = "nightly"
Expand Down Expand Up @@ -44,26 +47,34 @@ name = "governor_criterion_benches"
harness = false

[dev-dependencies]
crossbeam = "0.7.3"
more-asserts = "0.2.1"

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
criterion = "0.3.2"
tynm = "0.1.4"
crossbeam = "0.7.3"
libc = "0.2.70"
futures = "0.3.5"
proptest = "0.10.0"
more-asserts = "0.2.1"

[features]
default = ["std", "dashmap", "jitter", "quanta"]
std = ["no-std-compat/std", "nonzero_ext/std", "futures-timer", "futures"]
jitter = ["rand"]
stdweb = ["instant/stdweb"]
wasm-bindgen = ["futures-timer/wasm-bindgen", "instant/wasm-bindgen"]
no_std = []

[dependencies]
nonzero_ext = { version = "0.2.0", default-features = false }
parking_lot = "0.11.0"
futures-timer = { version = "3.0.2", optional = true }
futures = { version = "0.3.5", optional = true }
instant = "0.1.7"
rand = { version = "0.7.3", optional = true }
dashmap = { version = "3.11.1", optional = true }
quanta = { version = "0.4.1", optional = true }
no-std-compat = { version = "0.4.0", features = [ "alloc", "compat_hash" ] }

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-test = "0.3.12"
3 changes: 2 additions & 1 deletion benches/multi_threaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
use criterion::{black_box, BenchmarkId, Criterion, Throughput};
use governor::state::keyed::{DashMapStateStore, HashMapStateStore, KeyedStateStore};
use governor::{clock, Quota, RateLimiter};
use instant::Instant;
use nonzero_ext::*;
use std::sync::Arc;
use std::thread;
use std::time::{Duration, Instant};
use std::time::Duration;
use tynm::type_name;

pub fn bench_all(c: &mut Criterion) {
Expand Down
2 changes: 1 addition & 1 deletion src/clock/default.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(all(feature = "std", not(feature = "quanta")))]
/// The default clock that reports [`Instant`][std::time::Instant]s.
/// The default clock that reports [`Instant`][instant::Instant]s.
pub type DefaultClock = crate::clock::MonotonicClock;

#[cfg(all(feature = "std", feature = "quanta"))]
Expand Down
3 changes: 2 additions & 1 deletion src/clock/with_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use super::{Clock, Reference};
use std::prelude::v1::*;

use crate::nanos::Nanos;
use instant::Instant;
use std::ops::Add;
use std::time::{Duration, Instant, SystemTime};
use std::time::{Duration, SystemTime};

/// The monotonic clock implemented by [`Instant`].
#[derive(Clone, Debug, Default)]
Expand Down
2 changes: 1 addition & 1 deletion src/jitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::ops::Add;
use std::time::Duration;

#[cfg(feature = "std")]
use std::time::Instant;
use instant::Instant;

/// An interval specification for deviating from the nominal wait time.
///
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub use errors::*;
pub use gcra::NotUntil;
#[cfg(feature = "jitter")]
pub use jitter::Jitter;
#[cfg(all(not(feature = "std"), feature = "jitter"))]
#[cfg(all(not(feature = "jitter"), feature = "std"))]
pub(crate) use jitter::Jitter;
pub use quota::Quota;
#[doc(inline)]
Expand Down
10 changes: 10 additions & 0 deletions tests/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ use governor::{
use nonzero_ext::nonzero;
use std::time::Duration;

// Trick so we don't have to annotate each test with:
// #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[cfg(target_arch = "wasm32")]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

#[test]
fn accepts_first_cell() {
let clock = FakeRelativeClock::default();
Expand Down Expand Up @@ -141,6 +149,8 @@ fn correct_wait_time() {
assert_eq!(20, conforming);
}

// Crossbeam scoped threads are not supported on WASM
#[cfg(not(target_arch = "wasm32"))]
#[test]
fn actual_threadsafety() {
use crossbeam;
Expand Down
Loading

0 comments on commit 2da4a65

Please sign in to comment.