Remove From<u64> for Millis impl

This commit is contained in:
Nikolay Kim 2021-08-31 02:05:15 +06:00
parent 8007e9bc21
commit 96bb2b4590
23 changed files with 94 additions and 121 deletions

View file

@ -1,5 +1,9 @@
# Changes
## [0.4.0-b.7] - 2021-08-31
* Remove From<u64> for Millis impl
## [0.4.0-b.6] - 2021-08-30
* More timer wheel cleanups on driver drop

View file

@ -1,6 +1,6 @@
[package]
name = "ntex"
version = "0.4.0-b.6"
version = "0.4.0-b.7"
authors = ["ntex contributors <team@ntex.rs>"]
description = "Framework for composable network services"
readme = "README.md"

View file

@ -513,7 +513,7 @@ mod tests {
use crate::codec::BytesCodec;
use crate::testing::Io;
use crate::time::sleep;
use crate::time::{sleep, Millis};
use crate::util::Bytes;
use super::*;
@ -581,7 +581,7 @@ mod tests {
server,
BytesCodec,
crate::fn_service(|msg: DispatchItem<BytesCodec>| async move {
sleep(50).await;
sleep(Millis(50)).await;
if let DispatchItem::Item(msg) = msg {
Ok::<_, ()>(Some(msg.freeze()))
} else {
@ -632,7 +632,7 @@ mod tests {
assert_eq!(buf, Bytes::from_static(b"test"));
st.close();
sleep(1100).await;
sleep(Millis(1100)).await;
assert!(client.is_server_dropped());
}
@ -719,7 +719,7 @@ mod tests {
let buf = client.read_any();
assert_eq!(buf, Bytes::from_static(b""));
client.write("GET /test HTTP/1\r\n\r\n");
sleep(25).await;
sleep(Millis(25)).await;
// buf must be consumed
assert_eq!(client.remote_buffer(|buf| buf.len()), 0);
@ -729,11 +729,11 @@ mod tests {
assert_eq!(state.write().with_buf(|buf| buf.len()), 65536);
client.remote_buffer_cap(10240);
sleep(50).await;
sleep(Millis(50)).await;
assert_eq!(state.write().with_buf(|buf| buf.len()), 55296);
client.remote_buffer_cap(45056);
sleep(50).await;
sleep(Millis(50)).await;
assert_eq!(state.write().with_buf(|buf| buf.len()), 10240);
// backpressure disabled
@ -782,7 +782,7 @@ mod tests {
let buf = client.read().await.unwrap();
assert_eq!(buf, Bytes::from_static(b"GET /test HTTP/1\r\n\r\n"));
sleep(3000).await;
sleep(Millis(3000)).await;
// write side must be closed, dispatcher should fail with keep-alive
let flags = state.flags();
@ -808,7 +808,7 @@ mod tests {
crate::fn_service(move |msg: DispatchItem<BytesCodec>| {
handled2.store(true, Relaxed);
async move {
sleep(50).await;
sleep(Millis(50)).await;
if let DispatchItem::Item(msg) = msg {
Ok::<_, ()>(Some(msg.freeze()))
} else {
@ -821,7 +821,7 @@ mod tests {
crate::rt::spawn(async move {
let _ = disp.await;
});
sleep(50).await;
sleep(Millis(50)).await;
assert!(handled.load(Relaxed));
}

View file

@ -605,7 +605,7 @@ mod tests {
use super::*;
use crate::{
http::client::Connection, http::Uri, service::fn_service, testing::Io,
time::sleep, util::lazy,
util::lazy,
};
#[crate::rt_test]
@ -662,7 +662,7 @@ mod tests {
let mut fut = pool.call(req.clone());
assert!(lazy(|cx| Pin::new(&mut fut).poll(cx)).await.is_pending());
drop(fut);
sleep(50).await;
sleep(Millis(50)).await;
pool.1.borrow_mut().check_availibility();
assert!(pool.1.borrow().waiters.is_empty());

View file

@ -220,7 +220,7 @@ impl DateService {
// periodic date update
let s = self.clone();
crate::rt::spawn(async move {
sleep(500).await;
sleep(Millis(500)).await;
s.0.current.set(false);
});
}

View file

@ -740,7 +740,7 @@ mod tests {
use crate::http::{body, Request, ResponseHead, StatusCode};
use crate::service::{boxed, fn_service, IntoService};
use crate::util::{lazy, next, Bytes, BytesMut};
use crate::{codec::Decoder, testing::Io, time::sleep};
use crate::{codec::Decoder, testing::Io, time::sleep, time::Millis};
const BUFFER_SIZE: usize = 32_768;
@ -823,10 +823,10 @@ mod tests {
None,
None,
);
sleep(50).await;
sleep(Millis(50)).await;
assert!(lazy(|cx| Pin::new(&mut h1).poll(cx)).await.is_ready());
sleep(50).await;
sleep(Millis(50)).await;
client.local_buffer(|buf| assert_eq!(&buf[..15], b"HTTP/1.0 200 OK"));
client.close().await;
@ -842,11 +842,11 @@ mod tests {
let mut h1 = h1(server, |_| {
Box::pin(async { Ok::<_, io::Error>(Response::Ok().finish()) })
});
sleep(50).await;
sleep(Millis(50)).await;
assert!(lazy(|cx| Pin::new(&mut h1).poll(cx)).await.is_ready());
assert!(!h1.inner.state.is_open());
sleep(50).await;
sleep(Millis(50)).await;
client
.local_buffer(|buf| assert_eq!(&buf[..26], b"HTTP/1.1 400 Bad Request\r\n"));
@ -897,7 +897,7 @@ mod tests {
});
client.write("GET /test HTTP/1.1\r\ncontent-length: 5\r\n\r\n");
sleep(50).await;
sleep(Millis(50)).await;
client.write("xxxxx");
let mut buf = client.read().await.unwrap();
@ -921,7 +921,7 @@ mod tests {
client.remote_buffer_cap(4096);
let mut decoder = ClientCodec::default();
spawn_h1(server, |_| async {
sleep(100).await;
sleep(Millis(100)).await;
Ok::<_, io::Error>(Response::Ok().finish())
});
@ -933,7 +933,7 @@ mod tests {
client.write("GET /test HTTP/1.1\r\n\r\n");
client.write("GET /test HTTP/1.1\r\n\r\n");
sleep(50).await;
sleep(Millis(50)).await;
client.write("GET /test HTTP/1.1\r\n\r\n");
let mut buf = client.read().await.unwrap();
@ -998,10 +998,10 @@ mod tests {
.collect::<String>();
client.write("GET /test HTTP/1.1\r\nContent-Length: ");
client.write(data);
sleep(50).await;
sleep(Millis(50)).await;
assert!(lazy(|cx| Pin::new(&mut h1).poll(cx)).await.is_pending());
sleep(50).await;
sleep(Millis(50)).await;
assert!(lazy(|cx| Pin::new(&mut h1).poll(cx)).await.is_ready());
assert!(!h1.inner.state.is_open());
@ -1024,13 +1024,13 @@ mod tests {
let _ = next(&mut pl).await.unwrap().unwrap();
m.store(true, Ordering::Relaxed);
// sleep
sleep(999_999_000).await;
sleep(Millis(999_999_000)).await;
Ok::<_, io::Error>(Response::Ok().finish())
}
});
client.write("GET /test HTTP/1.1\r\nContent-Length: 1048576\r\n\r\n");
sleep(50).await;
sleep(Millis(50)).await;
// buf must be consumed
assert_eq!(client.remote_buffer(|buf| buf.len()), 0);
@ -1040,7 +1040,7 @@ mod tests {
(0..1_048_576).map(|_| rand::random::<u8>()).collect();
client.write(random_bytes);
sleep(50).await;
sleep(Millis(50)).await;
assert!(client.remote_buffer(|buf| buf.len()) > 1_048_576 - BUFFER_SIZE * 3);
assert!(mark.load(Ordering::Relaxed));
}
@ -1083,7 +1083,7 @@ mod tests {
// do not allow to write to socket
client.remote_buffer_cap(0);
client.write("GET /test HTTP/1.1\r\n\r\n");
sleep(50).await;
sleep(Millis(50)).await;
assert!(lazy(|cx| Pin::new(&mut h1).poll(cx)).await.is_pending());
// buf must be consumed
@ -1096,7 +1096,7 @@ mod tests {
assert_eq!(state.write().with_buf(|buf| buf.len()), 65629);
client.remote_buffer_cap(65536);
sleep(50).await;
sleep(Millis(50)).await;
assert_eq!(state.write().with_buf(|buf| buf.len()), 93);
assert!(lazy(|cx| Pin::new(&mut h1).poll(cx)).await.is_pending());
@ -1138,7 +1138,7 @@ mod tests {
});
client.write("GET /test HTTP/1.1\r\n\r\n");
sleep(50).await;
sleep(Millis(50)).await;
assert!(lazy(|cx| Pin::new(&mut h1).poll(cx)).await.is_pending());
// http message must be consumed
@ -1150,7 +1150,7 @@ mod tests {
assert!(lazy(|cx| Pin::new(&mut h1).poll(cx)).await.is_pending());
client.close().await;
sleep(50).await;
sleep(Millis(50)).await;
assert!(lazy(|cx| Pin::new(&mut h1).poll(cx)).await.is_ready());
}
@ -1165,10 +1165,10 @@ mod tests {
Err::<Response<()>, _>(io::Error::new(io::ErrorKind::Other, "error"))
})
});
sleep(50).await;
sleep(Millis(50)).await;
assert!(lazy(|cx| Pin::new(&mut h1).poll(cx)).await.is_ready());
sleep(50).await;
sleep(Millis(50)).await;
assert!(h1.inner.state.is_io_err());
let buf = client.local_buffer(|buf| buf.split().freeze());
assert_eq!(&buf[..28], b"HTTP/1.1 500 Internal Server");

View file

@ -7,7 +7,7 @@ use coo_kie::{Cookie, CookieJar};
use crate::codec::{AsyncRead, AsyncWrite, Framed};
use crate::rt::{net::TcpStream, System};
use crate::server::{Server, StreamServiceFactory};
use crate::{time::Seconds, util::Bytes};
use crate::{time::Millis, time::Seconds, util::Bytes};
use super::client::error::WsClientError;
use super::client::{Client, ClientRequest, ClientResponse, Connector};
@ -243,13 +243,13 @@ pub fn server<F: StreamServiceFactory<TcpStream>>(factory: F) -> TestServer {
.set_alpn_protos(b"\x02h2\x08http/1.1")
.map_err(|e| log::error!("Cannot set alpn protocol: {:?}", e));
Connector::default()
.timeout(30_000)
.timeout(Millis(30_000))
.openssl(builder.build())
.finish()
}
#[cfg(not(feature = "openssl"))]
{
Connector::default().timeout(30_000).finish()
Connector::default().timeout(Millis(30_000)).finish()
}
};

View file

@ -6,7 +6,7 @@ use log::{error, info};
use slab::Slab;
use crate::rt::System;
use crate::time::sleep;
use crate::time::{sleep, Millis};
use super::socket::{Listener, SocketAddr};
use super::worker::{Connection, WorkerClient};
@ -15,7 +15,7 @@ use super::{Server, ServerStatus, Token};
const DELTA: usize = 100;
const NOTIFY: mio::Token = mio::Token(0);
const ERR_TIMEOUT: Duration = Duration::from_millis(500);
const ERR_SLEEP_TIMEOUT: u64 = 525;
const ERR_SLEEP_TIMEOUT: Millis = Millis(525);
#[derive(Debug)]
pub(super) enum Command {

View file

@ -17,7 +17,7 @@ use super::socket::Listener;
use super::worker::{self, Worker, WorkerAvailability, WorkerClient};
use super::{Server, ServerCommand, ServerStatus, Token};
const STOP_DELAY: u64 = 300;
const STOP_DELAY: Millis = Millis(300);
/// Server builder
pub struct ServerBuilder {
@ -550,11 +550,11 @@ mod tests {
let h = start(tx);
let (srv, addr) = rx.recv().unwrap();
crate::time::sleep(300).await;
crate::time::sleep(Millis(300)).await;
assert!(net::TcpStream::connect(addr).is_ok());
srv.signal(*sig);
crate::time::sleep(300).await;
crate::time::sleep(Millis(300)).await;
assert!(net::TcpStream::connect(addr).is_err());
let _ = h.join();
}

View file

@ -31,6 +31,7 @@ pub(super) struct Connection {
pub(super) token: Token,
}
const STOP_TIMEOUT: Millis = Millis::ONE_SEC;
static MAX_CONNS: AtomicUsize = AtomicUsize::new(25600);
/// Sets the maximum per-worker number of concurrent connections.
@ -344,7 +345,7 @@ impl Future for Worker {
if num != 0 {
info!("Graceful worker shutdown, {} connections", num);
self.state = WorkerState::Shutdown(
sleep(1000),
sleep(STOP_TIMEOUT),
sleep(self.shutdown_timeout),
Some(result),
);
@ -433,7 +434,7 @@ impl Future for Worker {
match t1.poll_elapsed(cx) {
Poll::Pending => (),
Poll::Ready(_) => {
*t1 = sleep(1000);
*t1 = sleep(STOP_TIMEOUT);
let _ = t1.poll_elapsed(cx);
}
}

View file

@ -4,7 +4,7 @@ use std::task::{Context, Poll, Waker};
use std::{cmp, fmt, io, mem, pin::Pin};
use crate::codec::{AsyncRead, AsyncWrite, ReadBuf};
use crate::time::sleep;
use crate::time::{sleep, Millis};
use crate::util::{poll_fn, BytesMut};
#[derive(Default)]
@ -169,7 +169,7 @@ impl Io {
remote.read = IoState::Close;
remote.waker.wake();
}
sleep(35).await;
sleep(Millis(35)).await;
}
/// Add extra data to the remote buffer and notify reader

View file

@ -102,36 +102,6 @@ impl ops::Add<Millis> for std::time::Duration {
}
}
impl From<u64> for Millis {
#[inline]
fn from(millis: u64) -> Millis {
Millis(millis)
}
}
impl From<u128> for Millis {
#[inline]
fn from(d: u128) -> Millis {
Self(d.try_into().unwrap_or_else(|_| {
log::error!("time Duration is too large {:?}", d);
1 << 31
}))
}
}
impl From<i32> for Millis {
#[inline]
fn from(d: i32) -> Millis {
let millis = if d < 0 {
log::error!("time Duration is negative {:?}", d);
0
} else {
d as u64
};
Self(millis)
}
}
impl From<Seconds> for Millis {
#[inline]
fn from(s: Seconds) -> Millis {

View file

@ -559,7 +559,7 @@ mod tests {
#[crate::rt_test]
async fn test_timer() {
crate::rt::spawn(async {
let s = interval(25);
let s = interval(Millis(25));
loop {
s.tick().await;
}

View file

@ -1,8 +1,7 @@
use std::task::{Context, Poll};
use std::time::{Duration, Instant};
use std::{cell::Cell, convert::Infallible, marker};
use std::{cell::Cell, convert::Infallible, marker, time::Duration, time::Instant};
use crate::time::{sleep, Sleep};
use crate::time::{sleep, Millis, Sleep};
use crate::{util::Ready, Service, ServiceFactory};
use super::time::{LowResTime, LowResTimeService};
@ -12,7 +11,7 @@ use super::time::{LowResTime, LowResTimeService};
/// Controls min time between requests.
pub struct KeepAlive<R, E, F> {
f: F,
ka: Duration,
ka: Millis,
time: LowResTime,
_t: marker::PhantomData<(R, E)>,
}
@ -25,7 +24,7 @@ where
///
/// ka - keep-alive timeout
/// err - error factory function
pub fn new(ka: Duration, time: LowResTime, err: F) -> Self {
pub fn new(ka: Millis, time: LowResTime, err: F) -> Self {
KeepAlive {
ka,
time,
@ -72,7 +71,7 @@ where
pub struct KeepAliveService<R, E, F> {
f: F,
dur: Duration,
dur: Millis,
time: LowResTimeService,
sleep: Sleep,
expire: Cell<Instant>,
@ -83,8 +82,8 @@ impl<R, E, F> KeepAliveService<R, E, F>
where
F: Fn() -> E,
{
pub fn new(dur: Duration, time: LowResTimeService, f: F) -> Self {
let expire = Cell::new(time.now() + dur);
pub fn new(dur: Millis, time: LowResTimeService, f: F) -> Self {
let expire = Cell::new(time.now() + Duration::from(dur));
KeepAliveService {
f,
@ -114,7 +113,7 @@ where
Poll::Ready(Err((self.f)()))
} else {
let expire = self.expire.get() - Instant::now();
self.sleep.reset(expire.as_millis() as u64);
self.sleep.reset(Millis(expire.as_millis() as u64));
let _ = self.sleep.poll_elapsed(cx);
Poll::Ready(Ok(()))
}
@ -124,7 +123,7 @@ where
}
fn call(&self, req: R) -> Self::Future {
self.expire.set(self.time.now() + self.dur);
self.expire.set(self.time.now() + Duration::from(self.dur));
Ready::Ok(req)
}
}
@ -133,7 +132,6 @@ where
mod tests {
use super::*;
use crate::service::{Service, ServiceFactory};
use crate::time::sleep;
use crate::util::lazy;
#[derive(Debug, PartialEq)]
@ -142,7 +140,7 @@ mod tests {
#[crate::rt_test]
async fn test_ka() {
let factory =
KeepAlive::new(Duration::from_millis(100), LowResTime::new(10), || TestErr);
KeepAlive::new(Millis(100), LowResTime::new(Millis(10)), || TestErr);
let _ = factory.clone();
let service = factory.new_service(()).await.unwrap();
@ -150,7 +148,7 @@ mod tests {
assert_eq!(service.call(1usize).await, Ok(1usize));
assert!(lazy(|cx| service.poll_ready(cx)).await.is_ready());
sleep(500).await;
sleep(Millis(500)).await;
assert_eq!(
lazy(|cx| service.poll_ready(cx)).await,
Poll::Ready(Err(TestErr))

View file

@ -165,7 +165,7 @@ mod tests {
use super::*;
use crate::util::{next, ByteString, BytesMut};
use crate::{channel::mpsc, codec::Encoder, time::sleep, ws};
use crate::{channel::mpsc, codec::Encoder, time::sleep, time::Millis, ws};
#[crate::rt_test]
async fn test_basic() {
@ -200,7 +200,7 @@ mod tests {
assert_eq!(data, b"\x81\x04test".as_ref());
drop(tx);
sleep(10).await;
sleep(Millis(10)).await;
assert!(next(&mut rx).await.is_none());
assert_eq!(counter.get(), 1);

View file

@ -209,7 +209,7 @@ mod tests {
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap();
sleep(wait_time).await;
sleep(Millis(wait_time)).await;
let second_time = time_service
.now()
@ -231,7 +231,7 @@ mod tests {
let first_time = time_service.now();
sleep(wait_time).await;
sleep(Millis(wait_time)).await;
let second_time = time_service.now();
assert!(second_time - first_time >= Duration::from_millis(wait_time));

View file

@ -577,7 +577,7 @@ impl<Err: ErrorRenderer> ServiceFactory for ResourceEndpoint<Err> {
mod tests {
use crate::http::header::{self, HeaderValue};
use crate::http::{Method, StatusCode};
use crate::time::sleep;
use crate::time::{sleep, Millis};
use crate::web::middleware::DefaultHeaders;
use crate::web::request::WebRequest;
use crate::web::test::{call_service, init_service, TestRequest};
@ -659,7 +659,7 @@ mod tests {
async fn test_to() {
let srv =
init_service(App::new().service(web::resource("/test").to(|| async {
sleep(100).await;
sleep(Millis(100)).await;
HttpResponse::Ok()
})))
.await;

View file

@ -275,7 +275,7 @@ array_routes!(12, a, b, c, d, e, f, g, h, i, j, k, l);
#[cfg(test)]
mod tests {
use crate::http::{Method, StatusCode};
use crate::time::sleep;
use crate::time::{sleep, Millis};
use crate::util::Bytes;
use crate::web::test::{call_service, init_service, read_body, TestRequest};
use crate::web::{self, error, App, DefaultError, HttpResponse};
@ -297,16 +297,16 @@ mod tests {
)
}),
web::post().to(|| async {
sleep(100).await;
sleep(Millis(100)).await;
HttpResponse::Created()
}),
web::delete().to(|| async {
sleep(100).await;
sleep(Millis(100)).await;
Err::<HttpResponse, _>(error::ErrorBadRequest("err"))
}),
]))
.service(web::resource("/json").route(web::get().to(|| async {
sleep(25).await;
sleep(Millis(25)).await;
web::types::Json(MyObject {
name: "test".to_string(),
})

View file

@ -18,7 +18,7 @@ use crate::http::header::{HeaderName, HeaderValue, CONTENT_TYPE};
use crate::http::test::TestRequest as HttpTestRequest;
use crate::http::{HttpService, Method, Payload, Request, StatusCode, Uri, Version};
use crate::router::{Path, ResourceDef};
use crate::time::{sleep, Seconds};
use crate::time::{sleep, Millis, Seconds};
use crate::util::{next, Bytes, BytesMut, Extensions, Ready};
use crate::{
map_config, rt::System, server::Server, IntoService, IntoServiceFactory, Service,
@ -735,8 +735,8 @@ where
Connector::default()
.lifetime(Seconds::ZERO)
.keep_alive(Seconds(30))
.timeout(30_000)
.disconnect_timeout(3_000)
.timeout(Millis(30_000))
.disconnect_timeout(Millis(3_000))
.openssl(builder.build())
.finish()
}
@ -744,7 +744,7 @@ where
{
Connector::default()
.lifetime(Seconds::ZERO)
.timeout(30_000)
.timeout(Millis(30_000))
.finish()
}
};
@ -949,7 +949,7 @@ impl TestServer {
pub async fn stop(self) {
self.server.stop(true).await;
self.system.stop();
sleep(100).await;
sleep(Millis(100)).await;
}
}

View file

@ -17,7 +17,7 @@ use ntex::service::{map_config, pipeline_factory, Service};
use ntex::web::dev::AppConfig;
use ntex::web::middleware::Compress;
use ntex::web::{self, test, App, BodyEncoding, Error, HttpRequest, HttpResponse};
use ntex::{time::Seconds, util::Bytes};
use ntex::{time::Millis, time::Seconds, util::Bytes};
const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
Hello World Hello World Hello World Hello World Hello World \
@ -162,7 +162,7 @@ async fn test_form() {
async fn test_timeout() {
let srv = test::server(|| {
App::new().service(web::resource("/").route(web::to(|| async {
ntex::time::sleep(2000).await;
ntex::time::sleep(Millis(2000)).await;
HttpResponse::Ok().body(STR)
})))
});
@ -191,7 +191,7 @@ async fn test_timeout() {
async fn test_timeout_override() {
let srv = test::server(|| {
App::new().service(web::resource("/").route(web::to(|| async {
ntex::time::sleep(2000).await;
ntex::time::sleep(Millis(2000)).await;
HttpResponse::Ok().body(STR)
})))
});
@ -824,7 +824,7 @@ async fn client_read_until_eof() {
}
}
});
ntex::time::sleep(300).await;
ntex::time::sleep(Millis(300)).await;
// client request
let req = Client::build()

View file

@ -15,7 +15,7 @@ use ntex::http::test::server as test_server;
use ntex::http::{body, HttpService, Method, Request, Response, StatusCode, Version};
use ntex::service::{fn_factory_with_config, fn_service};
use ntex::util::{Bytes, BytesMut};
use ntex::{time::Seconds, web::error::InternalError};
use ntex::{time::Millis, time::Seconds, web::error::InternalError};
async fn load_body<S>(mut stream: S) -> Result<BytesMut, PayloadError>
where
@ -150,14 +150,14 @@ async fn test_h2_content_length() {
for i in 0..1 {
let req = srv
.srequest(Method::GET, &format!("/{}", i))
.timeout(30_000)
.timeout(Millis(30_000))
.send();
let response = req.await.unwrap();
assert_eq!(response.headers().get(&header), None);
let req = srv
.srequest(Method::HEAD, &format!("/{}", i))
.timeout(100_000)
.timeout(Millis(100_000))
.send();
let response = req.await.unwrap();
assert_eq!(response.headers().get(&header), None);
@ -166,7 +166,7 @@ async fn test_h2_content_length() {
for i in 1..3 {
let req = srv
.srequest(Method::GET, &format!("/{}", i))
.timeout(30_000)
.timeout(Millis(30_000))
.send();
let response = req.await.unwrap();
assert_eq!(response.headers().get(&header), Some(&value));

View file

@ -8,7 +8,7 @@ use ntex::http::test::server as test_server;
use ntex::http::{
body, header, HttpService, KeepAlive, Method, Request, Response, StatusCode,
};
use ntex::time::sleep;
use ntex::time::{sleep, Millis};
use ntex::{service::fn_service, time::Seconds, util::Bytes, web::error};
#[ntex::test]
@ -57,7 +57,7 @@ async fn test_expect_continue() {
let srv = test_server(|| {
HttpService::build()
.expect(fn_service(|req: Request| async move {
sleep(20).await;
sleep(Millis(20)).await;
if req.head().uri.query() == Some("yes=") {
Ok(req)
} else {
@ -215,7 +215,7 @@ async fn test_http1_keepalive_timeout() {
let mut data = vec![0; 1024];
let _ = stream.read(&mut data);
assert_eq!(&data[..17], b"HTTP/1.1 200 OK\r\n");
sleep(1100).await;
sleep(Millis(1100)).await;
let mut data = vec![0; 1024];
let res = stream.read(&mut data).unwrap();

View file

@ -16,7 +16,7 @@ use ntex::http::header::{
TRANSFER_ENCODING,
};
use ntex::http::{Method, StatusCode};
use ntex::time::{sleep, Seconds, Sleep};
use ntex::time::{sleep, Millis, Seconds, Sleep};
use ntex::util::Bytes;
use ntex::web::middleware::Compress;
@ -49,7 +49,7 @@ const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
struct TestBody {
data: Bytes,
chunk_size: usize,
delay: Pin<Box<Sleep>>,
delay: Sleep,
}
impl TestBody {
@ -57,7 +57,7 @@ impl TestBody {
TestBody {
data,
chunk_size,
delay: Box::pin(sleep(std::time::Duration::from_millis(10))),
delay: sleep(Millis(10)),
}
}
}
@ -71,7 +71,7 @@ impl futures::Stream for TestBody {
) -> Poll<Option<Self::Item>> {
ready!(Pin::new(&mut self.delay).poll(cx));
self.delay = Box::pin(sleep(std::time::Duration::from_millis(10)));
self.delay = sleep(Millis(10));
let chunk_size = std::cmp::min(self.chunk_size, self.data.len());
let chunk = self.data.split_to(chunk_size);
if chunk.is_empty() {
@ -882,7 +882,7 @@ async fn test_reading_deflate_encoding_large_random_rustls() {
// client request
let req = srv
.post("/")
.timeout(10_000)
.timeout(Millis(10_000))
.header(CONTENT_ENCODING, "deflate")
.send_stream(TestBody::new(Bytes::from(enc), 1024));
@ -933,7 +933,7 @@ async fn test_reading_deflate_encoding_large_random_rustls_h1() {
// client request
let req = srv
.post("/")
.timeout(10_000)
.timeout(Millis(10_000))
.header(CONTENT_ENCODING, "deflate")
.send_stream(TestBody::new(Bytes::from(enc), 1024));
@ -984,7 +984,7 @@ async fn test_reading_deflate_encoding_large_random_rustls_h2() {
// client request
let req = srv
.post("/")
.timeout(10_000)
.timeout(Millis(10_000))
.header(CONTENT_ENCODING, "deflate")
.send_stream(TestBody::new(Bytes::from(enc), 1024));