Skip to content

Commit

Permalink
assert that all futures are Send
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem committed Oct 3, 2023
1 parent 9950704 commit edcc240
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/future/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2046,6 +2046,59 @@ mod tests {
};
use tokio::time::sleep;

#[test]
fn futures_are_send() {
let cache = Cache::new(0);

fn is_send(_: impl Send) {}

// pub fns
is_send(cache.get(&()));
is_send(cache.get_with((), async {}));
is_send(cache.get_with_by_ref(&(), async {}));
#[allow(deprecated)]
is_send(cache.get_with_if((), async {}, |_| false));
is_send(cache.insert((), ()));
is_send(cache.invalidate(&()));
is_send(cache.optionally_get_with((), async { None }));
is_send(cache.optionally_get_with_by_ref(&(), async { None }));
is_send(cache.remove(&()));
is_send(cache.run_pending_tasks());
is_send(cache.try_get_with((), async { Err(()) }));
is_send(cache.try_get_with_by_ref(&(), async { Err(()) }));

// entry fns
is_send(cache.entry(()).or_default());
is_send(cache.entry(()).or_insert(()));
is_send(cache.entry(()).or_insert_with(async {}));
is_send(cache.entry(()).or_insert_with_if(async {}, |_| false));
is_send(cache.entry(()).or_optionally_insert_with(async { None }));
is_send(cache.entry(()).or_try_insert_with(async { Err(()) }));

// entry_by_ref fns
is_send(cache.entry_by_ref(&()).or_default());
is_send(cache.entry_by_ref(&()).or_insert(()));
is_send(cache.entry_by_ref(&()).or_insert_with(async {}));
is_send(
cache
.entry_by_ref(&())
.or_insert_with_if(async {}, |_| false),
);
is_send(
cache
.entry_by_ref(&())
.or_optionally_insert_with(async { None }),
);
is_send(
cache
.entry_by_ref(&())
.or_try_insert_with(async { Err(()) }),
);

// NOTE: is this fn really supposed to be public?
is_send(cache.invalidate_with_hash(&(), 0, true));
}

#[tokio::test]
async fn max_capacity_zero() {
let mut cache = Cache::new(0);
Expand Down

0 comments on commit edcc240

Please sign in to comment.