ref-method and command merge #4
|
|
@ -42,8 +42,8 @@ impl ClientApi {
|
|||
let mut buffer: [u8; 1024] = [0; 1024];
|
||||
let addr = host.parse().unwrap();
|
||||
let mut stream = TcpStream::connect_timeout(&addr, Duration::from_millis(1000))?;
|
||||
|
||||
let _ = stream.read(&mut buffer)?;
|
||||
|
||||
let _ = stream.read(&mut buffer)?;
|
||||
println!("data recieved: {:?}", &buffer[0..20]);
|
||||
match Commands::from(&buffer) {
|
||||
Commands::Request(None) => {
|
||||
|
|
@ -69,4 +69,4 @@ impl ClientApi {
|
|||
pub fn get_clients(&self) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,10 +143,8 @@ impl From<&[u8; 1024]> for Commands {
|
|||
#[cfg(test)]
|
||||
mod test_commands_v2 {
|
||||
#![feature(test)]
|
||||
extern crate test;
|
||||
use super::Commands;
|
||||
use std::collections::HashMap;
|
||||
use test::Bencher;
|
||||
use std::str::FromStr;
|
||||
use super::CommandParseError;
|
||||
|
||||
|
|
@ -167,9 +165,4 @@ mod test_commands_v2 {
|
|||
|
||||
println!("{:?}", command.to_string())
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn benchmark(b: &mut Bencher) {
|
||||
b.iter(|| {let a = Commands::from_str("!connect: host:192.168.0.1 name:\"michael-bailey\" uuid:123456-1234-1234-123456").unwrap();})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
10
src/main.rs
10
src/main.rs
|
|
@ -1,4 +1,4 @@
|
|||
#![feature(test)]
|
||||
//#![feature(test)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
mod client_api;
|
||||
|
|
@ -118,6 +118,8 @@ mod tests {
|
|||
use crate::client_api::ClientApi;
|
||||
use std::collections::HashMap;
|
||||
use crate::commands::Commands;
|
||||
use std::{thread, time};
|
||||
use std::time::Duration;
|
||||
|
||||
#[test]
|
||||
fn test_server_info() {
|
||||
|
|
@ -128,8 +130,12 @@ mod tests {
|
|||
|
||||
let server = Server::new(name, address, owner);
|
||||
let result = server.start();
|
||||
|
||||
assert_eq!(result.is_ok(), true);
|
||||
|
||||
let dur = time::Duration::from_millis(1000);
|
||||
thread::sleep(dur);
|
||||
|
||||
let api = ClientApi::get_info("127.0.0.1:6000");
|
||||
assert_eq!(api.is_ok(), true);
|
||||
if let Ok(api) = api {
|
||||
|
|
@ -159,4 +165,4 @@ mod tests {
|
|||
std::thread::sleep(std::time::Duration::from_secs(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue