fix tests
This commit is contained in:
@@ -8,6 +8,4 @@ port="${1}"
|
|||||||
|
|
||||||
db="$(mktemp)"
|
db="$(mktemp)"
|
||||||
|
|
||||||
export DATABASE_URL="sqlite://${db}"
|
exec ./target/debug/packager --port "${port}" --database-url "sqlite://${db}"
|
||||||
|
|
||||||
exec ./target/debug/packager --port "${port}"
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use std::thread;
|
|||||||
use thirtyfour::common::capabilities::firefox::FirefoxPreferences;
|
use thirtyfour::common::capabilities::firefox::FirefoxPreferences;
|
||||||
use thirtyfour::{FirefoxCapabilities, WebDriver};
|
use thirtyfour::{FirefoxCapabilities, WebDriver};
|
||||||
|
|
||||||
|
use std::io::Read;
|
||||||
use std::time;
|
use std::time;
|
||||||
|
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
@@ -85,9 +86,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut handle_gecko = {
|
let mut handle_gecko = {
|
||||||
let script = concat!(env!("CARGO_MANIFEST_DIR"), "/../run-test-instance.sh");
|
println!("[sub] starting geckodriver");
|
||||||
|
|
||||||
println!("[sub] starting script {script}");
|
|
||||||
let handle = Command::new("geckodriver")
|
let handle = Command::new("geckodriver")
|
||||||
.stdin(Stdio::null())
|
.stdin(Stdio::null())
|
||||||
.stdout(Stdio::null())
|
.stdout(Stdio::null())
|
||||||
@@ -112,9 +111,9 @@ where
|
|||||||
println!("[sub] starting script {script}");
|
println!("[sub] starting script {script}");
|
||||||
let handle = Command::new(script)
|
let handle = Command::new(script)
|
||||||
.arg(PORT.to_string())
|
.arg(PORT.to_string())
|
||||||
.stdin(Stdio::null())
|
.stdin(Stdio::piped())
|
||||||
.stdout(Stdio::null())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::null())
|
.stderr(Stdio::piped())
|
||||||
.spawn()?;
|
.spawn()?;
|
||||||
println!("[sub] app started");
|
println!("[sub] app started");
|
||||||
handle
|
handle
|
||||||
@@ -122,16 +121,58 @@ where
|
|||||||
|
|
||||||
{
|
{
|
||||||
let (lock, cvar) = &*event_in_subprocess;
|
let (lock, cvar) = &*event_in_subprocess;
|
||||||
let mut done = lock.lock().unwrap();
|
println!("[sub] waiting for done event");
|
||||||
while !*done {
|
loop {
|
||||||
println!("[sub] waiting for done event");
|
let done = lock.try_lock();
|
||||||
done = cvar.wait(done).unwrap();
|
if let Ok(mut done) = done {
|
||||||
|
println!("could get mutex");
|
||||||
|
while !*done {
|
||||||
|
(done, _) = cvar
|
||||||
|
.wait_timeout(done, time::Duration::from_millis(1000))
|
||||||
|
.unwrap();
|
||||||
|
if handle_app.try_wait()?.is_some() {
|
||||||
|
println!("[sub] app died");
|
||||||
|
println!("[sub] killing gecko subprocess");
|
||||||
|
let _ = handle_gecko.kill()?;
|
||||||
|
handle_gecko.wait()?;
|
||||||
|
println!("[sub] killed gecko subprocess");
|
||||||
|
let mut output = String::new();
|
||||||
|
handle_app
|
||||||
|
.stdout
|
||||||
|
.take()
|
||||||
|
.unwrap()
|
||||||
|
.read_to_string(&mut output)
|
||||||
|
.unwrap();
|
||||||
|
handle_app
|
||||||
|
.stderr
|
||||||
|
.take()
|
||||||
|
.unwrap()
|
||||||
|
.read_to_string(&mut output)
|
||||||
|
.unwrap();
|
||||||
|
println!("{}", output);
|
||||||
|
return Err(TestError::AppError {
|
||||||
|
message: format!("app died: {}", output),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if handle_gecko.try_wait()?.is_some() {
|
||||||
|
println!("[sub] gecko died");
|
||||||
|
println!("[sub] killing app subprocess");
|
||||||
|
let _ = handle_app.kill()?;
|
||||||
|
handle_app.wait()?;
|
||||||
|
println!("[sub] killed app subprocess");
|
||||||
|
return Err(TestError::AppError {
|
||||||
|
message: "gecko died".to_string(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
thread::sleep(time::Duration::from_secs(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("[sub] done received");
|
println!("[sub] done received");
|
||||||
}
|
}
|
||||||
|
|
||||||
// at worst, the child already exited, so we don't care about the
|
|
||||||
// return code
|
|
||||||
println!("[sub] killing app subprocess");
|
println!("[sub] killing app subprocess");
|
||||||
let _ = handle_app.kill()?;
|
let _ = handle_app.kill()?;
|
||||||
handle_app.wait()?;
|
handle_app.wait()?;
|
||||||
@@ -264,28 +305,28 @@ async fn check_table(
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test() -> Result<(), TestError> {
|
async fn test() -> Result<(), TestError> {
|
||||||
let mut handle = {
|
// let mut handle = {
|
||||||
let script = concat!(env!("CARGO_MANIFEST_DIR"), "/../run-test-instance.sh");
|
// let script = concat!(env!("CARGO_MANIFEST_DIR"), "/../run-test-instance.sh");
|
||||||
|
|
||||||
println!("[sub] starting script {script}");
|
// println!("[sub] starting script {script}");
|
||||||
let handle = Command::new(script)
|
// let handle = Command::new(script)
|
||||||
.arg(PORT.to_string())
|
// .arg(PORT.to_string())
|
||||||
.stdin(Stdio::null())
|
// .stdin(Stdio::null())
|
||||||
.stdout(Stdio::null())
|
// .stdout(Stdio::null())
|
||||||
.stderr(Stdio::null())
|
// .stderr(Stdio::null())
|
||||||
.spawn()?;
|
// .spawn()?;
|
||||||
println!("[sub] started");
|
// println!("[sub] started");
|
||||||
handle
|
// handle
|
||||||
};
|
// };
|
||||||
|
|
||||||
// at worst, the child already exited, so we don't care about the
|
// // at worst, the child already exited, so we don't care about the
|
||||||
// return code
|
// // return code
|
||||||
println!("[sub] killing subprocess");
|
// println!("[sub] killing subprocess");
|
||||||
let _ = handle.kill().expect("failed to kill child");
|
// let _ = handle.kill().expect("failed to kill child");
|
||||||
handle.wait().unwrap();
|
// handle.wait().unwrap();
|
||||||
println!("[sub] killed subprocess");
|
// println!("[sub] killed subprocess");
|
||||||
|
|
||||||
println!("[sub] done");
|
// println!("[sub] done");
|
||||||
|
|
||||||
// return Ok(());
|
// return Ok(());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user