Skip to content

Commit 46749c1

Browse files
committed
test(client): fix background thread panics
1 parent 74195bc commit 46749c1

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

tests/client.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ mod dispatch_impl {
940940
let (closes_tx, closes) = mpsc::channel(10);
941941

942942
let (tx1, rx1) = oneshot::channel();
943-
let (_client_drop_tx, client_drop_rx) = oneshot::channel::<()>();
943+
let (_client_drop_tx, client_drop_rx) = std::sync::mpsc::channel::<()>();
944944

945945
thread::spawn(move || {
946946
let mut sock = server.accept().unwrap().0;
@@ -954,7 +954,7 @@ mod dispatch_impl {
954954

955955
// prevent this thread from closing until end of test, so the connection
956956
// stays open and idle until Client is dropped
957-
Runtime::new().unwrap().block_on(client_drop_rx.into_future()).unwrap();
957+
let _ = client_drop_rx.recv();
958958
});
959959

960960
let res = {
@@ -989,7 +989,7 @@ mod dispatch_impl {
989989
let (closes_tx, closes) = mpsc::channel(10);
990990

991991
let (tx1, rx1) = oneshot::channel();
992-
let (_client_drop_tx, client_drop_rx) = oneshot::channel::<()>();
992+
let (_client_drop_tx, client_drop_rx) = std::sync::mpsc::channel::<()>();
993993

994994
thread::spawn(move || {
995995
let mut sock = server.accept().unwrap().0;
@@ -1002,7 +1002,7 @@ mod dispatch_impl {
10021002

10031003
// prevent this thread from closing until end of test, so the connection
10041004
// stays open and idle until Client is dropped
1005-
Runtime::new().unwrap().block_on(client_drop_rx.into_future()).unwrap();
1005+
let _ = client_drop_rx.recv();
10061006
});
10071007

10081008
let res = {
@@ -1039,7 +1039,7 @@ mod dispatch_impl {
10391039
let (closes_tx, closes) = mpsc::channel(10);
10401040

10411041
let (tx1, rx1) = oneshot::channel();
1042-
let (_tx2, rx2) = oneshot::channel::<()>();
1042+
let (_tx2, rx2) = std::sync::mpsc::channel::<()>();
10431043

10441044
thread::spawn(move || {
10451045
let mut sock = server.accept().unwrap().0;
@@ -1049,7 +1049,10 @@ mod dispatch_impl {
10491049
sock.read(&mut buf).expect("read 1");
10501050
sock.write_all(b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n").unwrap();
10511051
let _ = tx1.send(());
1052-
let _ = Runtime::new().unwrap().block_on(rx2).unwrap();
1052+
1053+
// prevent this thread from closing until end of test, so the connection
1054+
// stays open and idle until Client is dropped
1055+
let _ = rx2.recv();
10531056
});
10541057

10551058
let client = Client::builder()

0 commit comments

Comments
 (0)