mirror of
https://github.com/ntex-rs/ntex.git
synced 2025-04-04 13:27:39 +03:00
Improve tests coverage (#161)
* improve tests coverage * update base64 crate
This commit is contained in:
parent
9bf0908f41
commit
fc7553b8bc
21 changed files with 137 additions and 51 deletions
|
@ -70,10 +70,19 @@ impl Extensions {
|
|||
|
||||
impl fmt::Debug for Extensions {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("Extensions").finish()
|
||||
f.debug_struct("Extensions")
|
||||
.field("size", &self.map.len())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_debug() {
|
||||
let mut map = Extensions::new();
|
||||
map.insert::<i8>(123);
|
||||
assert_eq!(format!("{:?}", map), "Extensions { size: 1 }");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_remove() {
|
||||
let mut map = Extensions::new();
|
||||
|
|
|
@ -9,6 +9,7 @@ use super::counter::{Counter, CounterGuard};
|
|||
/// async requests.
|
||||
///
|
||||
/// Default number of in-flight requests is 15
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct InFlight {
|
||||
max_inflight: usize,
|
||||
}
|
||||
|
@ -131,7 +132,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[ntex_macros::rt_test2]
|
||||
async fn test_transform() {
|
||||
async fn test_inflight() {
|
||||
let wait_time = Duration::from_millis(50);
|
||||
|
||||
let srv = InFlightService::new(1, SleepService(wait_time));
|
||||
|
@ -146,9 +147,14 @@ mod tests {
|
|||
}
|
||||
|
||||
#[ntex_macros::rt_test2]
|
||||
async fn test_newtransform() {
|
||||
let wait_time = Duration::from_millis(50);
|
||||
async fn test_middleware() {
|
||||
assert_eq!(InFlight::default().max_inflight, 15);
|
||||
assert_eq!(
|
||||
format!("{:?}", InFlight::new(1)),
|
||||
"InFlight { max_inflight: 1 }"
|
||||
);
|
||||
|
||||
let wait_time = Duration::from_millis(50);
|
||||
let srv = apply(
|
||||
InFlight::new(1),
|
||||
fn_factory(|| async { Ok::<_, ()>(SleepService(wait_time)) }),
|
||||
|
|
|
@ -183,7 +183,7 @@ impl Deadline {
|
|||
/// Returns `true` if `Deadline` has elapsed.
|
||||
#[inline]
|
||||
pub fn is_elapsed(&self) -> bool {
|
||||
self.hnd.as_ref().map(|t| t.is_elapsed()).unwrap_or(false)
|
||||
self.hnd.as_ref().map(|t| t.is_elapsed()).unwrap_or(true)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -439,6 +439,13 @@ mod tests {
|
|||
let mut dl = deadline(Millis(1));
|
||||
dl.reset(Millis::ZERO);
|
||||
assert!(lazy(|cx| dl.poll_elapsed(cx)).await.is_pending());
|
||||
|
||||
let mut dl = deadline(Millis(0));
|
||||
assert!(dl.is_elapsed());
|
||||
dl.reset(Millis(1));
|
||||
assert!(lazy(|cx| dl.poll_elapsed(cx)).await.is_pending());
|
||||
|
||||
assert!(format!("{:?}", dl).contains("Deadline"));
|
||||
}
|
||||
|
||||
#[ntex_macros::rt_test2]
|
||||
|
|
|
@ -244,5 +244,8 @@ mod tests {
|
|||
|
||||
let s = Seconds::new(10) + Seconds::new(10);
|
||||
assert_eq!(s.seconds(), 20);
|
||||
|
||||
assert_eq!(Seconds(0).map(|_| 1usize), None);
|
||||
assert_eq!(Seconds(2).map(|_| 1usize), Some(1));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue