Skip to content

Commit

Permalink
test: fix disconnect-body test
Browse files Browse the repository at this point in the history
  • Loading branch information
jbr committed May 31, 2024
1 parent 3d71146 commit 3fb8da6
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions api/tests/disconnect-body.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use async_channel::Sender;
use test_harness::test;
use trillium::{async_trait, Conn, Handler, Status};
use trillium::{Conn, Handler, Status};
use trillium_testing::{
futures_lite::AsyncWriteExt, harness, AsyncWrite, ClientConfig, Connector, ObjectSafeConnector,
client_config, futures_lite::AsyncWriteExt, harness, ArcedConnector, AsyncWrite, Connector,
ServerHandle,
};

struct LastStatus(Sender<Option<Status>>);

#[async_trait]
impl Handler for LastStatus {
async fn run(&self, conn: Conn) -> Conn {
conn
}

async fn before_send(&self, conn: Conn) -> Conn {
self.0.send(conn.status()).await.unwrap();
conn
Expand All @@ -35,7 +35,7 @@ async fn disconnect_on_string_body() {

drop(client);
assert_eq!(Some(Status::BadRequest), receiver.recv().await.unwrap());
handle.stop().await;
handle.shut_down().await;
}

/// this test exists to confirm that the 400 response tested above is in fact due to the disconnect
Expand All @@ -54,7 +54,7 @@ async fn normal_string_body() {

drop(client);
assert_eq!(Some(Status::Ok), receiver.recv().await.unwrap());
handle.stop().await;
handle.shut_down().await;
}

#[test(harness)]
Expand All @@ -73,7 +73,7 @@ async fn disconnect_on_vec_body() {

drop(client);
assert_eq!(Some(Status::BadRequest), receiver.recv().await.unwrap());
handle.stop().await;
handle.shut_down().await;
}

/// this test exists to confirm that the 400 response tested above is in fact due to the disconnect
Expand All @@ -92,7 +92,7 @@ async fn normal_vec_body() {

drop(client);
assert_eq!(Some(Status::Ok), receiver.recv().await.unwrap());
handle.stop().await;
handle.shut_down().await;
}

async fn establish_server(handler: impl Handler) -> (ServerHandle, impl AsyncWrite) {
Expand All @@ -112,11 +112,9 @@ async fn establish_server(handler: impl Handler) -> (ServerHandle, impl AsyncWri
|x| x.port(),
);

let client = Connector::connect(
&ClientConfig::default().boxed(),
&format!("http://localhost:{port}").parse().unwrap(),
)
.await
.unwrap();
let client = ArcedConnector::new(client_config())
.connect(&format!("http://localhost:{port}").parse().unwrap())
.await
.unwrap();
(handle, client)
}

0 comments on commit 3fb8da6

Please sign in to comment.