diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..82d8b9f17 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,67 @@ +language: rust +rust: + - 1.20.0 + - stable + - beta + - nightly + +sudo: required +dist: trusty + +services: + - redis-server + +env: + global: + - RUSTFLAGS="-C link-dead-code" + +addons: + apt: + packages: + - libcurl4-openssl-dev + - libelf-dev + - libdw-dev + - cmake + - gcc + - binutils-dev + - libiberty-dev + +# Add clippy +before_script: + - | + if [[ "$TRAVIS_RUST_VERSION" == "nightly" ]]; then + ( ( cargo install clippy && export CLIPPY=true ) || export CLIPPY=false ); + fi + - export PATH=$PATH:~/.cargo/bin + +script: + - | + if [[ "$TRAVIS_RUST_VERSION" == "nightly" ]]; then + USE_SKEPTIC=1 cargo test + else + cargo test + cd examples/chat && cargo check && cd ../.. + fi + - | + if [[ "$TRAVIS_RUST_VERSION" == "nightly" && $CLIPPY ]]; then + cargo clippy + fi + +# Upload docs +after_success: + - | + if [[ "$TRAVIS_OS_NAME" == "linux" && "$TRAVIS_PULL_REQUEST" = "false" && "$TRAVIS_BRANCH" == "master" && "$TRAVIS_RUST_VERSION" == "stable" ]]; then + cargo doc --no-deps && + echo "" > target/doc/index.html && + git clone https://github.com/davisp/ghp-import.git && + ./ghp-import/ghp_import.py -n -p -f -m "Documentation upload" -r https://"$GH_TOKEN"@github.com/"$TRAVIS_REPO_SLUG.git" target/doc && + echo "Uploaded documentation" + fi + + - | + if [[ "$TRAVIS_OS_NAME" == "linux" && "$TRAVIS_RUST_VERSION" == "nightly" ]]; then + bash <(curl https://raw.githubusercontent.com/xd009642/tarpaulin/master/travis-install.sh) + USE_SKEPTIC=1 cargo tarpaulin --out Xml + bash <(curl -s https://codecov.io/bash) + echo "Uploaded code coverage" + fi diff --git a/Cargo.toml b/Cargo.toml index 3fe330e44..ddef1c8c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ default = ["web"] web = ["actix-web", "cookie", "http", "rand", "serde", "serde_json"] [dependencies] -actix = "^0.4.3" +actix = "^0.4.5" log = "0.4" backoff = "0.1" diff --git a/src/lib.rs b/src/lib.rs index 29146b9d9..a5b40f4fa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,7 @@ extern crate trust_dns_resolver; mod redis; mod connect; -pub use redis::RedisActor; +pub use redis::{Command, RedisActor}; pub use connect::TcpConnector; #[cfg(feature="web")] @@ -56,3 +56,7 @@ impl From for Error { Error::Redis(err) } } + +// re-export +pub use redis_async::resp::RespValue; +pub use redis_async::error::Error as RespError; diff --git a/src/redis.rs b/src/redis.rs index a369dfacd..ddaebdd95 100644 --- a/src/redis.rs +++ b/src/redis.rs @@ -14,7 +14,7 @@ use redis_async::resp::{RespCodec, RespValue}; use Error; use connect::TcpConnector; -#[derive(Message)] +#[derive(Message, Debug)] #[rtype(RespValue, Error)] pub struct Command(pub RespValue); diff --git a/tests/test_redis.rs b/tests/test_redis.rs new file mode 100644 index 000000000..2123c7e1b --- /dev/null +++ b/tests/test_redis.rs @@ -0,0 +1,68 @@ +extern crate actix; +extern crate actix_redis; +#[macro_use] +extern crate redis_async; +extern crate futures; +extern crate env_logger; + +use actix::prelude::*; +use actix_redis::{RedisActor, Command, Error, RespValue}; +use futures::Future; + +#[test] +fn test_error_connect() { + let sys = System::new("test"); + + let addr = RedisActor::start("localhost:54000"); + let _addr2 = addr.clone(); + + Arbiter::handle().spawn_fn(move || { + addr.call_fut(Command(resp_array!["GET", "test"])) + .then(|res| { + match res { + Ok(Err(Error::NotConnected)) => (), + _ => panic!("Should not happen {:?}", res), + } + Arbiter::system().send(actix::msgs::SystemExit(0)); + Ok(()) + }) + }); + + sys.run(); +} + + +#[test] +fn test_redis() { + env_logger::init(); + let sys = System::new("test"); + + let addr = RedisActor::start("127.0.0.1:6379"); + let _addr2 = addr.clone(); + + Arbiter::handle().spawn_fn(move || { + let addr2 = addr.clone(); + addr.call_fut(Command(resp_array!["SET", "test", "value"])) + .then(move |res| match res { + Ok(Ok(resp)) => { + assert_eq!(resp, RespValue::SimpleString("OK".to_owned())); + addr2.call_fut(Command(resp_array!["GET", "test"])) + .then(|res| { + match res { + Ok(Ok(resp)) => { + println!("RESP: {:?}", resp); + assert_eq!( + resp, RespValue::BulkString((&b"value"[..]).into())); + }, + _ => panic!("Should not happen {:?}", res), + } + Arbiter::system().send(actix::msgs::SystemExit(0)); + Ok(()) + }) + }, + _ => panic!("Should not happen {:?}", res), + }) + }); + + sys.run(); +}