adding init wait
This commit is contained in:
parent
9a82607385
commit
cb1096d1e1
@ -91,6 +91,7 @@ impl<S> Worker<S> where S: IpcInterface<S> {
|
||||
match socket.nb_read_to_end(&mut self.buf) {
|
||||
Ok(method_sign_len) => {
|
||||
if method_sign_len >= 2 {
|
||||
|
||||
// method_num
|
||||
let method_num = self.buf[1] as u16 * 256 + self.buf[0] as u16;
|
||||
// payload
|
||||
@ -186,7 +187,6 @@ mod service_tests {
|
||||
fn dummy_write(addr: &str, buf: &[u8]) -> (Socket, Endpoint) {
|
||||
let mut socket = Socket::new(Protocol::Pair).unwrap();
|
||||
let endpoint = socket.connect(addr).unwrap();
|
||||
//thread::sleep_ms(10);
|
||||
socket.write(buf).unwrap();
|
||||
(socket, endpoint)
|
||||
}
|
||||
|
@ -29,25 +29,33 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
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());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_call_handshake() {
|
||||
let exit = Arc::new(::std::sync::atomic::AtomicBool::new(false));
|
||||
let url = "ipc:///tmp/parity-test-examples-20.ipc";
|
||||
let worker_should_exit = Arc::new(::std::sync::atomic::AtomicBool::new(false));
|
||||
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 || {
|
||||
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 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());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user