run regression test with local docker image instead of actual server
This commit is contained in:
parent
accfe7acbb
commit
c2d242453e
@ -144,10 +144,18 @@ fn vs_production() -> Result<(), DynError> {
|
|||||||
|
|
||||||
fn regression() -> Result<(), DynError> {
|
fn regression() -> Result<(), DynError> {
|
||||||
let mut snake = run_snake(8000, Some("error"))?;
|
let mut snake = run_snake(8000, Some("error"))?;
|
||||||
|
let mut prod = match run_production(8001) {
|
||||||
|
Ok(prod) => prod,
|
||||||
|
err => {
|
||||||
|
snake.kill()?;
|
||||||
|
err?;
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let res = try_regression();
|
let res = try_regression();
|
||||||
|
|
||||||
snake.kill()?;
|
snake.kill().and(prod.kill())?;
|
||||||
let (won, games) = res?;
|
let (won, games) = res?;
|
||||||
println!(
|
println!(
|
||||||
"\nThe local snake has won {won}/{games} games ({}%)",
|
"\nThe local snake has won {won}/{games} games ({}%)",
|
||||||
@ -157,10 +165,10 @@ fn regression() -> Result<(), DynError> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn try_regression() -> Result<(usize, usize), DynError> {
|
fn try_regression() -> Result<(usize, usize), DynError> {
|
||||||
const GAMES: usize = 1000;
|
const GAMES: usize = 100;
|
||||||
// use only 4 threads so we don't ddos the server
|
// limit the parallelism
|
||||||
rayon::ThreadPoolBuilder::new()
|
rayon::ThreadPoolBuilder::new()
|
||||||
.num_threads(4)
|
.num_threads(std::thread::available_parallelism()?.get() / 3)
|
||||||
.build_global()
|
.build_global()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@ -168,7 +176,6 @@ fn try_regression() -> Result<(usize, usize), DynError> {
|
|||||||
.into_par_iter()
|
.into_par_iter()
|
||||||
.map(|_| -> Option<usize> {
|
.map(|_| -> Option<usize> {
|
||||||
eprint!(".");
|
eprint!(".");
|
||||||
// let _ = stderr().flush();
|
|
||||||
let game = Command::new("./battlesnake-cli")
|
let game = Command::new("./battlesnake-cli")
|
||||||
.current_dir(project_root())
|
.current_dir(project_root())
|
||||||
.args([
|
.args([
|
||||||
@ -184,7 +191,7 @@ fn try_regression() -> Result<(usize, usize), DynError> {
|
|||||||
"--name",
|
"--name",
|
||||||
"production",
|
"production",
|
||||||
"--url",
|
"--url",
|
||||||
"https://snake.mkaenner.de",
|
"http://localhost:8001",
|
||||||
"-g",
|
"-g",
|
||||||
"duel",
|
"duel",
|
||||||
])
|
])
|
||||||
@ -235,6 +242,30 @@ fn run_snake(port: u16, log: Option<&str>) -> Result<Child, DynError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn run_production(port: u16) -> Result<Child, DynError> {
|
||||||
|
let mut snake = Command::new("docker")
|
||||||
|
.args([
|
||||||
|
"run",
|
||||||
|
"--env",
|
||||||
|
"RUST_LOG=error",
|
||||||
|
"--env",
|
||||||
|
format!("ROCKET_PORT={}", port).as_str(),
|
||||||
|
"--network=host",
|
||||||
|
"-i",
|
||||||
|
"docker.mkaenner.de/snake:latest",
|
||||||
|
])
|
||||||
|
.spawn()?;
|
||||||
|
loop {
|
||||||
|
if let Some(status) = snake.try_wait()? {
|
||||||
|
Err(format!("{status}"))?;
|
||||||
|
}
|
||||||
|
if TcpStream::connect(("127.0.0.1", port)).is_ok() {
|
||||||
|
break Ok(snake);
|
||||||
|
}
|
||||||
|
sleep(Duration::from_secs(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn docker() -> Result<(), DynError> {
|
fn docker() -> Result<(), DynError> {
|
||||||
if !Command::new("docker")
|
if !Command::new("docker")
|
||||||
.current_dir(project_root())
|
.current_dir(project_root())
|
||||||
|
Loading…
Reference in New Issue
Block a user