adding init wait
This commit is contained in:
parent
98ab30d102
commit
593ccd2510
@ -91,6 +91,7 @@ impl<S> Worker<S> where S: IpcInterface<S> {
|
|||||||
match socket.nb_read_to_end(&mut self.buf) {
|
match socket.nb_read_to_end(&mut self.buf) {
|
||||||
Ok(method_sign_len) => {
|
Ok(method_sign_len) => {
|
||||||
if method_sign_len >= 2 {
|
if method_sign_len >= 2 {
|
||||||
|
|
||||||
// method_num
|
// method_num
|
||||||
let method_num = self.buf[1] as u16 * 256 + self.buf[0] as u16;
|
let method_num = self.buf[1] as u16 * 256 + self.buf[0] as u16;
|
||||||
// payload
|
// payload
|
||||||
@ -186,7 +187,6 @@ mod service_tests {
|
|||||||
fn dummy_write(addr: &str, buf: &[u8]) -> (Socket, Endpoint) {
|
fn dummy_write(addr: &str, buf: &[u8]) -> (Socket, Endpoint) {
|
||||||
let mut socket = Socket::new(Protocol::Pair).unwrap();
|
let mut socket = Socket::new(Protocol::Pair).unwrap();
|
||||||
let endpoint = socket.connect(addr).unwrap();
|
let endpoint = socket.connect(addr).unwrap();
|
||||||
//thread::sleep_ms(10);
|
|
||||||
socket.write(buf).unwrap();
|
socket.write(buf).unwrap();
|
||||||
(socket, endpoint)
|
(socket, endpoint)
|
||||||
}
|
}
|
||||||
|
@ -29,25 +29,33 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_create_client() {
|
fn can_create_client() {
|
||||||
let client = nanoipc::init_client::<ServiceClient<_>>("ipc:///tmp/parity-examples-test10.ipc");
|
let client = nanoipc::init_client::<ServiceClient<_>>("ipc:///tmp/parity-nano-test10.ipc");
|
||||||
assert!(client.is_ok());
|
assert!(client.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_call_handshake() {
|
fn can_call_handshake() {
|
||||||
let exit = Arc::new(::std::sync::atomic::AtomicBool::new(false));
|
let worker_should_exit = Arc::new(::std::sync::atomic::AtomicBool::new(false));
|
||||||
let url = "ipc:///tmp/parity-test-examples-20.ipc";
|
let worker_is_ready = Arc::new(::std::sync::atomic::AtomicBool::new(false));
|
||||||
|
let c_worker_should_exit = worker_should_exit.clone();
|
||||||
|
let c_worker_is_ready = worker_is_ready.clone();
|
||||||
|
|
||||||
|
let url = "ipc:///tmp/parity-test-nano-20.ipc";
|
||||||
|
|
||||||
let worker_exit = exit.clone();
|
|
||||||
::std::thread::spawn(move || {
|
::std::thread::spawn(move || {
|
||||||
let mut worker = init_worker(url);
|
let mut worker = init_worker(url);
|
||||||
while !worker_exit.load(::std::sync::atomic::Ordering::Relaxed) { worker.poll() }
|
while !c_worker_should_exit.load(::std::sync::atomic::Ordering::Relaxed) {
|
||||||
|
worker.poll();
|
||||||
|
c_worker_is_ready.store(true, ::std::sync::atomic::Ordering::Relaxed);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
while !worker_is_ready.load(::std::sync::atomic::Ordering::Relaxed) { }
|
||||||
let client = nanoipc::init_client::<ServiceClient<_>>(url).unwrap();
|
let client = nanoipc::init_client::<ServiceClient<_>>(url).unwrap();
|
||||||
|
|
||||||
let hs = client.handshake();
|
let hs = client.handshake();
|
||||||
|
|
||||||
exit.store(true, ::std::sync::atomic::Ordering::Relaxed);
|
worker_should_exit.store(true, ::std::sync::atomic::Ordering::Relaxed);
|
||||||
assert!(hs.is_ok());
|
assert!(hs.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user