Skip to content

Commit

Permalink
[api] add client test module, remove test crate
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Jul 7, 2018
1 parent abdfda2 commit 163ad3b
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 54 deletions.
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ version = "0.3.0"

members = [
"rain_client",
"rain_client_test",
"rain_core",
"rain_server",
"rain_task",
Expand Down
44 changes: 44 additions & 0 deletions rain_client/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,47 @@ impl Client {
}
}

#[cfg(test)]
mod tests {
use super::super::localcluster::LocalCluster;
use super::super::tasks::CommonTasks;
use super::Client;
use super::Session;
use std::env;

#[allow(dead_code)]
struct TestContext {
cluster: LocalCluster,
client: Client,
session: Session,
}

fn ctx() -> TestContext {
let rain = env::var("RAIN_BINARY").unwrap();

let cluster = LocalCluster::new(&rain).unwrap();
let client = cluster.create_client().unwrap();
let session = client.new_session().unwrap();

TestContext {
cluster,
client,
session,
}
}

#[test]
fn concat() {
let mut ctx = ctx();
let a = ctx.session.blob(vec![1, 2, 3]);
let b = ctx.session.blob(vec![4, 5, 6]);
let c = ctx.session.concat(&[a, b]);
c.output().keep();
ctx.session.submit().unwrap();
ctx.session.wait(&[c.clone()], &[]).unwrap();
assert_eq!(
ctx.session.fetch(&c.output()).unwrap(),
vec![1, 2, 3, 4, 5, 6]
);
}
}
11 changes: 5 additions & 6 deletions rain_client/src/client/localcluster.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
use super::client::Client;
use std::error::Error;
use std::net::SocketAddr;
use super::client::Client;
use std::process::{Child, Command};
use std::path::PathBuf;
use std::{thread, time};
use std::process::Stdio;
use std::process::{Command, Stdio};

pub struct LocalCluster {
listen_addr: SocketAddr,
binary: PathBuf
binary: PathBuf,
}

impl LocalCluster {
pub fn new(binary: &str) -> Result<Self, Box<Error>> {
let mut cluster = LocalCluster {
binary: PathBuf::from(binary),
listen_addr: SocketAddr::new("127.0.0.1".parse()?, 7210)
listen_addr: SocketAddr::new("127.0.0.1".parse()?, 7210),
};
cluster.start()?;

Expand Down Expand Up @@ -43,6 +41,7 @@ impl LocalCluster {
}

impl Drop for LocalCluster {
#![allow(unused_must_use)]
fn drop(&mut self) {
Client::new(self.listen_addr).unwrap().terminate_server();
}
Expand Down
4 changes: 2 additions & 2 deletions rain_client/src/client/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod client;
pub mod localcluster;
pub mod session;
pub mod tasks;
pub mod localcluster;

#[macro_use]
mod rpc;
Expand All @@ -10,5 +10,5 @@ mod dataobject;
mod task;

pub use self::client::Client;
pub use self::session::Session;
pub use self::localcluster::LocalCluster;
pub use self::session::Session;
3 changes: 2 additions & 1 deletion rain_client/src/client/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ impl Session {
}

impl Drop for Session {
#![allow(unused_must_use)]
fn drop(&mut self) {
self.comm.close_session(self.id).unwrap();
debug!("Session {} destroyed", self.id);
self.comm.close_session(self.id);
}
}
10 changes: 0 additions & 10 deletions rain_client_test/Cargo.toml

This file was deleted.

27 changes: 0 additions & 27 deletions rain_client_test/src/main.rs

This file was deleted.

0 comments on commit 163ad3b

Please sign in to comment.