From 4e72608441bc2c3df457747ffe9f2b0306fafa4a Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Mon, 1 Aug 2016 16:32:07 +0300 Subject: [PATCH] Fix ipc tests and bring to CI (#1789) * fixed compilation * Fix warnings * fix remaining tests * add to ci and fix test.sh --- Cargo.lock | 16 ++++++++++++ Cargo.toml | 2 ++ devtools/src/test_socket.rs | 3 ++- ipc/tests/Cargo.toml | 3 ++- ipc/tests/binary.rs.in | 8 ++++++ ipc/tests/examples.rs | 49 +++++-------------------------------- ipc/tests/nested.rs.in | 8 +++--- ipc/tests/run.rs | 1 + ipc/tests/service.rs.in | 3 +-- ipc/tests/with_attrs.rs.in | 4 +-- scripts/targets.sh | 1 + test.sh | 2 +- 12 files changed, 44 insertions(+), 56 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 906bbb0fc..cbc2c25de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,6 +15,7 @@ dependencies = [ "ethcore-ipc-codegen 1.3.0", "ethcore-ipc-hypervisor 1.2.0", "ethcore-ipc-nano 1.3.0", + "ethcore-ipc-tests 0.1.0", "ethcore-logger 1.3.0", "ethcore-rpc 1.3.0", "ethcore-signer 1.3.0", @@ -358,6 +359,21 @@ dependencies = [ "nanomsg 0.5.1 (git+https://github.com/ethcore/nanomsg.rs.git)", ] +[[package]] +name = "ethcore-ipc-tests" +version = "0.1.0" +dependencies = [ + "ethcore-devtools 1.3.0", + "ethcore-ipc 1.3.0", + "ethcore-ipc-codegen 1.3.0", + "ethcore-ipc-nano 1.3.0", + "ethcore-util 1.3.0", + "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "nanomsg 0.5.1 (git+https://github.com/ethcore/nanomsg.rs.git)", + "semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "syntex 0.33.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "ethcore-logger" version = "1.3.0" diff --git a/Cargo.toml b/Cargo.toml index bf35a1697..162194b6b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ build = "build.rs" rustc_version = "0.1" syntex = "*" ethcore-ipc-codegen = { path = "ipc/codegen" } +ethcore-ipc-tests = { path = "ipc/tests" } [dependencies] log = "0.3" @@ -58,6 +59,7 @@ use-precompiled-js = ["ethcore-dapps/use-precompiled-js", "ethcore-signer/use-pr dapps = ["ethcore-dapps"] dev = ["clippy", "ethcore/dev", "ethcore-util/dev", "ethsync/dev", "ethcore-rpc/dev", "ethcore-dapps/dev", "ethcore-signer/dev"] ipc = ["ethcore/ipc"] +json-tests = ["ethcore/json-tests"] [[bin]] path = "parity/main.rs" diff --git a/devtools/src/test_socket.rs b/devtools/src/test_socket.rs index c740e872a..0d38e66a5 100644 --- a/devtools/src/test_socket.rs +++ b/devtools/src/test_socket.rs @@ -62,6 +62,7 @@ impl TestSocket { impl Read for TestSocket { fn read(&mut self, buf: &mut [u8]) -> Result { let end_position = cmp::min(self.read_buffer.len(), self.cursor+buf.len()); + if self.cursor > end_position { return Ok(0) } let len = cmp::max(end_position - self.cursor, 0); match len { 0 => Ok(0), @@ -69,7 +70,7 @@ impl Read for TestSocket { for i in self.cursor..end_position { buf[i-self.cursor] = self.read_buffer[i]; } - self.cursor = self.cursor + buf.len(); + self.cursor = end_position; Ok(len) } } diff --git a/ipc/tests/Cargo.toml b/ipc/tests/Cargo.toml index d9c80145d..61903434f 100644 --- a/ipc/tests/Cargo.toml +++ b/ipc/tests/Cargo.toml @@ -10,10 +10,11 @@ path = "run.rs" [dependencies] ethcore-ipc = { path = "../rpc" } ethcore-devtools = { path = "../../devtools" } -semver = "0.2.0" +semver = "0.2" nanomsg = { git = "https://github.com/ethcore/nanomsg.rs.git" } ethcore-ipc-nano = { path = "../nano" } ethcore-util = { path = "../../util" } +log = "0.3" [build-dependencies] syntex = "0.33" diff --git a/ipc/tests/binary.rs.in b/ipc/tests/binary.rs.in index fd017e340..b9b263f66 100644 --- a/ipc/tests/binary.rs.in +++ b/ipc/tests/binary.rs.in @@ -56,3 +56,11 @@ fn opt_two_vec() { let serialized = ::ipc::binary::serialize(&example).unwrap(); assert_eq!(serialized, vec![0u8; 16]); } + +#[test] +fn enum_with_struct() { + let example = EnumWithStruct::Right { how_much: 15 }; + let serialized = ::ipc::binary::serialize(&example).unwrap(); + let deserialized = ::ipc::binary::deserialize::(&serialized).unwrap(); + assert_eq!(example, deserialized); +} diff --git a/ipc/tests/examples.rs b/ipc/tests/examples.rs index 7afcd583d..a27c0637a 100644 --- a/ipc/tests/examples.rs +++ b/ipc/tests/examples.rs @@ -42,38 +42,6 @@ mod tests { assert_eq!(10, *service.commits.read().unwrap()); } - - #[test] - fn call_service_handshake() { - let mut socket = TestSocket::new_ready(vec![0, 0, - // part count = 3 - 3, 0, 0, 0, 0, 0, 0, 0, - // part sizes - 5, 0, 0, 0, 0, 0, 0, 0, - 5, 0, 0, 0, 0, 0, 0, 0, - 64, 0, 0, 0, 0, 0, 0, 0, - // total payload length - 70, 0, 0, 0, 0, 0, 0, 0, - // protocol version - b'1', b'.', b'0', b'.', b'0', - // api version - b'1', b'.', b'0', b'.', b'0', - // reserved - - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); - - let service = Arc::new(Service::new()); - let result = service.dispatch(&mut socket); - - // single `true` - assert_eq!(vec![1], result); - } - - #[test] fn call_service_client() { let mut socket = TestSocket::new(); @@ -110,9 +78,9 @@ mod tests { #[test] fn query_default_version() { - let ver = Arc::::protocol_version(); + let ver = Service::protocol_version(); assert_eq!(ver, Version::parse("1.0.0").unwrap()); - let ver = Arc::::api_version(); + let ver = Service::api_version(); assert_eq!(ver, Version::parse("1.0.0").unwrap()); } @@ -153,16 +121,11 @@ mod tests { #[test] fn can_invoke_generic_service() { let mut socket = TestSocket::new(); - socket.read_buffer = vec![ - 1, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, - 0, - ]; + socket.read_buffer = vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; let db_client = DBClient::::init(socket); - - let result = db_client.write(vec![0u8; 100]); - + let result = db_client.write(vec![1u8; 1]); + assert_eq!(vec![0, 16, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1], + db_client.socket().write().unwrap().write_buffer.clone()); assert!(result.is_ok()); } diff --git a/ipc/tests/nested.rs.in b/ipc/tests/nested.rs.in index c249799f2..6b4b2b325 100644 --- a/ipc/tests/nested.rs.in +++ b/ipc/tests/nested.rs.in @@ -15,9 +15,7 @@ // along with Parity. If not, see . use std::sync::RwLock; -use std::ops::*; use ipc::IpcConfig; -use ipc::BinaryConvertable; use std::mem; use ipc::binary::BinaryConvertError; use std::collections::VecDeque; @@ -29,11 +27,11 @@ pub struct DB { } pub trait DBWriter { - fn write(&self, data: Vec) -> Result<(), DBError>; + fn write(&self, data: Vec) -> Result<(), DBError>; fn write_slice(&self, data: &[u8]) -> Result<(), DBError>; } -impl IpcConfig for ::std::sync::Arc {} +impl IpcConfig for DBWriter {} #[derive(Binary)] pub enum DBError { Write, Read } @@ -58,4 +56,4 @@ trait DBNotify { fn notify(&self, a: u64, b: u64) -> bool; } -impl IpcConfig for ::std::sync::Arc { } +impl IpcConfig for DBNotify { } diff --git a/ipc/tests/run.rs b/ipc/tests/run.rs index ab0041899..522f566cf 100644 --- a/ipc/tests/run.rs +++ b/ipc/tests/run.rs @@ -22,6 +22,7 @@ extern crate semver; extern crate nanomsg; extern crate ethcore_ipc_nano as nanoipc; extern crate ethcore_util as util; +#[macro_use] extern crate log; pub mod service; mod examples; diff --git a/ipc/tests/service.rs.in b/ipc/tests/service.rs.in index 1e3d235e5..ec403ce6e 100644 --- a/ipc/tests/service.rs.in +++ b/ipc/tests/service.rs.in @@ -15,7 +15,6 @@ // along with Parity. If not, see . use std::sync::RwLock; -use std::ops::*; use ipc::IpcConfig; use std::mem; use ipc::binary::BinaryConvertError; @@ -70,4 +69,4 @@ impl Service { } } -impl ::ipc::IpcConfig for ::std::sync::Arc {} +impl ::ipc::IpcConfig for Service {} diff --git a/ipc/tests/with_attrs.rs.in b/ipc/tests/with_attrs.rs.in index 8458667ef..240e434c9 100644 --- a/ipc/tests/with_attrs.rs.in +++ b/ipc/tests/with_attrs.rs.in @@ -14,8 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use std::sync::RwLock; -use std::ops::*; use ipc::IpcConfig; use std::mem; use ipc::binary::BinaryConvertError; @@ -31,4 +29,4 @@ impl BadlyNamedService { } } -impl ::ipc::IpcConfig for ::std::sync::Arc {} +impl IpcConfig for BadlyNamedService {} diff --git a/scripts/targets.sh b/scripts/targets.sh index 331353c3f..0885bf2c8 100644 --- a/scripts/targets.sh +++ b/scripts/targets.sh @@ -12,4 +12,5 @@ export TARGETS=" -p ethstore \ -p ethsync \ -p ethcore-ipc \ + -p ethcore-ipc-tests \ -p parity" diff --git a/test.sh b/test.sh index 18a7bb6b6..773a7127e 100755 --- a/test.sh +++ b/test.sh @@ -1,7 +1,7 @@ #!/bin/sh # Running Parity Full Test Sute -FEATURES="--features ethcore/json-tests" +FEATURES="--features json-tests" case $1 in --no-json)