Skip to content

Commit 7a1c1f4

Browse files
committed
Make http test work
1 parent 701ed6d commit 7a1c1f4

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

core-client/src/transports/http.rs

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//! HTTP client
22
3-
use hyper::{http, Client, Request};
3+
use hyper::{http, rt, Client, Request};
44
use futures::{Future, Stream};
55

66
use crate::{RpcChannel, RpcError};
77
use super::request_response;
88

99
/// Create a HTTP Client
10-
pub fn http<TClient>(url: &str) -> impl Future<Item=TClient, Error=()>
10+
pub fn http<TClient>(url: &str) -> impl Future<Item=TClient, Error=RpcError>
1111
where
1212
TClient: From<RpcChannel>,
1313
{
@@ -32,9 +32,10 @@ where
3232
})
3333
});
3434

35-
rpc_client
36-
.map_err(|e| log::error!("RPC Client error: {:?}", e))
37-
.map(|()| TClient::from(sender))
35+
rt::lazy(move|| {
36+
rt::spawn(rpc_client.map_err(|e| log::error!("RPC Client error: {:?}", e)));
37+
Ok(TClient::from(sender))
38+
})
3839
}
3940

4041
#[cfg(test)]
@@ -44,6 +45,7 @@ mod tests {
4445
use hyper::rt;
4546
use super::*;
4647
use crate::*;
48+
use std::time::Duration;
4749

4850
fn id<T>(t: T) -> T {
4951
t
@@ -91,20 +93,26 @@ mod tests {
9193
// given
9294
let _server = serve(id);
9395

96+
let (tx, rx) = std::sync::mpsc::channel();
9497
let uri = "http://localhost:3030";
98+
99+
// when
95100
let run =
96101
http(uri)
97102
.and_then(|client: TestClient| {
98103
client.hello("http")
99-
.then(|result| {
100-
assert_eq!(result.unwrap(), "hello http");
104+
.and_then(move |result| {
101105
drop(client);
106+
let _ = tx.send(result);
102107
Ok(())
103108
})
104-
});
109+
})
110+
.map_err(|e| log::error!("RPC Client error: {:?}", e));
105111

106112
rt::run(run);
107113

108-
assert!(false);
114+
// then
115+
let result = rx.recv_timeout(Duration::from_secs(3)).unwrap();
116+
assert_eq!("hello http", result);
109117
}
110118
}

derive/tests/client.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use futures::prelude::*;
2-
use jsonrpc_core_client::local;
2+
use jsonrpc_core_client::transports::local;
33
use jsonrpc_core::{IoHandler, Result};
44
use jsonrpc_derive::rpc;
55

@@ -35,4 +35,4 @@ fn client_server_roundtrip() {
3535
assert!(false);
3636
});
3737
tokio::run(fut);
38-
}
38+
}

0 commit comments

Comments
 (0)