mirror of
https://github.com/ntex-rs/ntex.git
synced 2025-04-04 05:17:39 +03:00
Improve tests
This commit is contained in:
parent
eb4ec4b3e1
commit
653c5302b5
2 changed files with 17 additions and 9 deletions
|
@ -114,6 +114,7 @@ flate2 = { version = "1.0", optional = true }
|
|||
[dev-dependencies]
|
||||
rand = "0.8"
|
||||
time = "0.3"
|
||||
oneshot = "0.1"
|
||||
futures-util = "0.3"
|
||||
tls-openssl = { version = "0.10", package = "openssl" }
|
||||
tls-rustls = { version = "0.23", package = "rustls", features = ["ring", "std"], default-features = false }
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::sync::{atomic::AtomicUsize, atomic::Ordering, Arc};
|
||||
use std::sync::{atomic::AtomicUsize, atomic::Ordering, Arc, Mutex};
|
||||
use std::{io, io::Read, io::Write, net};
|
||||
|
||||
use futures_util::future::{self, FutureExt};
|
||||
|
@ -761,12 +761,18 @@ async fn test_h1_client_drop() -> io::Result<()> {
|
|||
async fn test_h1_gracefull_shutdown() {
|
||||
let count = Arc::new(AtomicUsize::new(0));
|
||||
let count2 = count.clone();
|
||||
let (tx, rx) = ::oneshot::channel();
|
||||
let tx = Arc::new(Mutex::new(Some(tx)));
|
||||
|
||||
let srv = test_server(move || {
|
||||
let tx = tx.clone();
|
||||
let count = count2.clone();
|
||||
HttpService::build().h1(move |_: Request| {
|
||||
let count = count.clone();
|
||||
count.fetch_add(1, Ordering::Relaxed);
|
||||
if count.load(Ordering::Relaxed) == 2 {
|
||||
let _ = tx.lock().unwrap().take().unwrap().send(());
|
||||
}
|
||||
async move {
|
||||
sleep(Millis(1000)).await;
|
||||
count.fetch_sub(1, Ordering::Relaxed);
|
||||
|
@ -781,7 +787,7 @@ async fn test_h1_gracefull_shutdown() {
|
|||
let mut stream2 = net::TcpStream::connect(srv.addr()).unwrap();
|
||||
let _ = stream2.write_all(b"GET /index.html HTTP/1.1\r\n\r\n");
|
||||
|
||||
sleep(Millis(150)).await;
|
||||
let _ = rx.await;
|
||||
assert_eq!(count.load(Ordering::Relaxed), 2);
|
||||
|
||||
let (tx, rx) = oneshot::channel();
|
||||
|
@ -789,8 +795,6 @@ async fn test_h1_gracefull_shutdown() {
|
|||
srv.stop().await;
|
||||
let _ = tx.send(());
|
||||
});
|
||||
sleep(Millis(150)).await;
|
||||
assert_eq!(count.load(Ordering::Relaxed), 2);
|
||||
|
||||
let _ = rx.await;
|
||||
assert_eq!(count.load(Ordering::Relaxed), 0);
|
||||
|
@ -800,12 +804,18 @@ async fn test_h1_gracefull_shutdown() {
|
|||
async fn test_h1_gracefull_shutdown_2() {
|
||||
let count = Arc::new(AtomicUsize::new(0));
|
||||
let count2 = count.clone();
|
||||
let (tx, rx) = ::oneshot::channel();
|
||||
let tx = Arc::new(Mutex::new(Some(tx)));
|
||||
|
||||
let srv = test_server(move || {
|
||||
let tx = tx.clone();
|
||||
let count = count2.clone();
|
||||
HttpService::build().finish(move |_: Request| {
|
||||
let count = count.clone();
|
||||
count.fetch_add(1, Ordering::Relaxed);
|
||||
if count.load(Ordering::Relaxed) == 2 {
|
||||
let _ = tx.lock().unwrap().take().unwrap().send(());
|
||||
}
|
||||
async move {
|
||||
sleep(Millis(1000)).await;
|
||||
count.fetch_sub(1, Ordering::Relaxed);
|
||||
|
@ -820,17 +830,14 @@ async fn test_h1_gracefull_shutdown_2() {
|
|||
let mut stream2 = net::TcpStream::connect(srv.addr()).unwrap();
|
||||
let _ = stream2.write_all(b"GET /index.html HTTP/1.1\r\n\r\n");
|
||||
|
||||
sleep(Millis(150)).await;
|
||||
assert_eq!(count.load(Ordering::Relaxed), 2);
|
||||
let _ = rx.await;
|
||||
assert_eq!(count.load(Ordering::Acquire), 2);
|
||||
|
||||
let (tx, rx) = oneshot::channel();
|
||||
rt::spawn(async move {
|
||||
srv.stop().await;
|
||||
let _ = tx.send(());
|
||||
});
|
||||
sleep(Millis(150)).await;
|
||||
assert_eq!(count.load(Ordering::Relaxed), 2);
|
||||
|
||||
let _ = rx.await;
|
||||
assert_eq!(count.load(Ordering::Relaxed), 0);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue