test: improve coverage (#231)

* feat(ntex-glommio): remove unused mut

* test(ntex-io): check Debug implementation for FilterServiceFactory

* chore: format code

* feat(ntex-util): check Debug and poll_ready for KeepAlive

* test(ntex-util): wait a bit until the poll is ready

* test(ntex-bytes): assert error for implementation try_from for BytesVec

* feat(ntex-tokio): remove unused mut

* feat(ntex-tls): use add_trust_anchors instead of add_server_trust_anchors

* chore: format code

* feat(ntex-util): check readiness after sleeping but before expiring

* feat(ntex-util): remove unnecessary assertion
This commit is contained in:
msga-mmm 2023-10-17 08:14:40 -05:00 committed by GitHub
parent bd49962d1b
commit 9bb4a60ad4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 21 deletions

View file

@ -406,12 +406,6 @@ mod test {
s.clear();
assert_eq!(s, "");
assert!(ByteString::try_from(b"\xc3\x28".as_ref()).is_err());
assert!(ByteString::try_from(vec![b'\xc3']).is_err());
assert!(ByteString::try_from(Bytes::from_static(b"\xc3\x28")).is_err());
assert!(ByteString::try_from(&Bytes::from_static(b"\xc3\x28")).is_err());
assert!(ByteString::try_from(BytesMut::copy_from_slice(b"\xc3\x28")).is_err());
}
#[test]
@ -465,12 +459,23 @@ mod test {
#[test]
fn test_try_from() {
let _ = ByteString::try_from(&b"nice bytes"[..]).unwrap();
assert!(ByteString::try_from(b"\xc3\x28".as_ref()).is_err());
let _ = ByteString::try_from(b"nice bytes".to_vec()).unwrap();
assert!(ByteString::try_from(vec![b'\xc3']).is_err());
let _ = ByteString::try_from(Bytes::from_static(b"nice bytes")).unwrap();
assert!(ByteString::try_from(Bytes::from_static(b"\xc3\x28")).is_err());
let _ = ByteString::try_from(&Bytes::from_static(b"nice bytes")).unwrap();
assert!(ByteString::try_from(&Bytes::from_static(b"\xc3\x28")).is_err());
let _ = ByteString::try_from(BytesMut::from(&b"nice bytes"[..])).unwrap();
assert!(ByteString::try_from(BytesMut::copy_from_slice(b"\xc3\x28")).is_err());
let _ =
ByteString::try_from(BytesVec::copy_from_slice(&b"nice bytes"[..])).unwrap();
assert!(ByteString::try_from(BytesVec::copy_from_slice(b"\xc3\x28")).is_err());
}
#[test]

View file

@ -133,7 +133,7 @@ impl Future for WriteTask {
type Output = ();
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let mut this = self.as_mut().get_mut();
let this = self.as_mut().get_mut();
match this.st {
IoWriteState::Processing(ref mut delay) => {
@ -441,7 +441,7 @@ impl Future for UnixWriteTask {
type Output = ();
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let mut this = self.as_mut().get_mut();
let this = self.as_mut().get_mut();
match this.st {
IoWriteState::Processing(ref mut delay) => {

View file

@ -159,18 +159,22 @@ mod tests {
#[ntex::test]
async fn test_utils_filter() {
let (_, server) = IoTest::create();
let svc = chain_factory(
filter::<_, crate::filter::Base>(TestFilterFactory)
.map_err(|_| ())
.map_init_err(|_| ()),
)
.and_then(seal(fn_service(|io: IoBoxed| async move {
let _ = io.recv(&BytesCodec).await;
Ok::<_, ()>(())
})))
.pipeline(())
.await
.unwrap();
let filter_service_factory = filter::<_, crate::filter::Base>(TestFilterFactory)
.map_err(|_| ())
.map_init_err(|_| ());
assert!(format!("{:?}", filter_service_factory).contains("FilterServiceFactory"));
let svc = chain_factory(filter_service_factory)
.and_then(seal(fn_service(|io: IoBoxed| async move {
let _ = io.recv(&BytesCodec).await;
Ok::<_, ()>(())
})))
.pipeline(())
.await
.unwrap();
let _ = svc.call(Io::new(server)).await;
}

View file

@ -102,7 +102,7 @@ impl Future for Signals {
{
if self.signal.as_mut().poll(cx).is_ready() {
let handlers = SHANDLERS.with(|h| mem::take(&mut *h.borrow_mut()));
for mut sender in handlers {
for sender in handlers {
let _ = sender.send(Signal::Int);
}
}

View file

@ -151,9 +151,11 @@ mod tests {
#[ntex_macros::rt_test2]
async fn test_ka() {
let factory = KeepAlive::new(Millis(100), || TestErr);
assert!(format!("{:?}", factory).contains("KeepAlive"));
let _ = factory.clone();
let service = factory.pipeline(&()).await.unwrap();
assert!(format!("{:?}", service).contains("KeepAliveService"));
assert_eq!(service.call(1usize).await, Ok(1usize));
assert!(lazy(|cx| service.poll_ready(cx)).await.is_ready());