2020-04-17 12:11:25 +00:00
|
|
|
use anyhow::{bail, Error};
|
2019-04-11 06:26:52 +00:00
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate proxmox_backup;
|
|
|
|
|
|
|
|
extern crate tokio;
|
|
|
|
extern crate nix;
|
|
|
|
|
2020-01-22 09:08:40 +00:00
|
|
|
use proxmox::try_block;
|
2019-08-05 08:04:12 +00:00
|
|
|
|
2021-09-10 10:45:06 +00:00
|
|
|
use pbs_api_types::{Authid, UPID};
|
|
|
|
|
2019-04-11 06:26:52 +00:00
|
|
|
use proxmox_backup::server;
|
|
|
|
use proxmox_backup::tools;
|
|
|
|
|
|
|
|
fn garbage_collection(worker: &server::WorkerTask) -> Result<(), Error> {
|
|
|
|
|
|
|
|
worker.log("start garbage collection");
|
|
|
|
|
|
|
|
for i in 0..50 {
|
|
|
|
worker.fail_on_abort()?;
|
|
|
|
|
|
|
|
flog!(worker, "progress {}", i);
|
|
|
|
|
|
|
|
std::thread::sleep(std::time::Duration::from_millis(10));
|
|
|
|
}
|
|
|
|
|
|
|
|
worker.log("end garbage collection");
|
|
|
|
|
2021-01-15 13:38:27 +00:00
|
|
|
Ok(())
|
2019-04-11 06:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-14 08:42:44 +00:00
|
|
|
#[test]
|
|
|
|
#[ignore]
|
2019-04-11 06:26:52 +00:00
|
|
|
fn worker_task_abort() -> Result<(), Error> {
|
|
|
|
|
|
|
|
server::create_task_log_dirs()?;
|
|
|
|
|
|
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
|
|
|
|
let errmsg: Arc<Mutex<Option<String>>> = Arc::new(Mutex::new(None));
|
|
|
|
let errmsg1 = errmsg.clone();
|
|
|
|
|
2020-12-04 10:53:34 +00:00
|
|
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
2019-08-29 08:05:43 +00:00
|
|
|
rt.block_on(async move {
|
2019-04-11 06:26:52 +00:00
|
|
|
|
2020-11-02 18:13:36 +00:00
|
|
|
let mut commando_sock = server::CommandoSocket::new(server::our_ctrl_sock());
|
|
|
|
|
2019-04-11 06:26:52 +00:00
|
|
|
let init_result: Result<(), Error> = try_block!({
|
2020-11-02 18:13:36 +00:00
|
|
|
server::register_task_control_commands(&mut commando_sock)?;
|
2019-04-11 06:26:52 +00:00
|
|
|
server::server_state_init()?;
|
|
|
|
Ok(())
|
|
|
|
});
|
|
|
|
|
|
|
|
if let Err(err) = init_result {
|
|
|
|
eprintln!("unable to start daemon - {}", err);
|
2019-08-29 08:05:43 +00:00
|
|
|
return;
|
2019-04-11 06:26:52 +00:00
|
|
|
}
|
|
|
|
|
2021-09-14 08:42:44 +00:00
|
|
|
if let Err(err) = commando_sock.spawn() {
|
|
|
|
eprintln!("unable to spawn command socket - {}", err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-11 06:26:52 +00:00
|
|
|
let errmsg = errmsg1.clone();
|
2020-08-06 13:46:01 +00:00
|
|
|
let res = server::WorkerTask::new_thread(
|
|
|
|
"garbage_collection",
|
|
|
|
None,
|
2021-09-10 10:45:06 +00:00
|
|
|
Authid::root_auth_id().clone(),
|
2020-08-06 13:46:01 +00:00
|
|
|
true,
|
|
|
|
move |worker| {
|
|
|
|
println!("WORKER {}", worker);
|
|
|
|
|
|
|
|
let result = garbage_collection(&worker);
|
|
|
|
tools::request_shutdown();
|
|
|
|
|
|
|
|
if let Err(err) = result {
|
|
|
|
println!("got expected error: {}", err);
|
|
|
|
} else {
|
|
|
|
let mut data = errmsg.lock().unwrap();
|
|
|
|
*data = Some(String::from("thread finished - seems abort did not work as expected"));
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
},
|
|
|
|
);
|
2019-04-11 06:26:52 +00:00
|
|
|
|
|
|
|
match res {
|
|
|
|
Err(err) => {
|
|
|
|
println!("unable to start worker - {}", err);
|
|
|
|
}
|
|
|
|
Ok(wid) => {
|
|
|
|
println!("WORKER: {}", wid);
|
2021-09-10 10:45:06 +00:00
|
|
|
server::abort_worker_async(wid.parse::<UPID>().unwrap());
|
2021-09-14 08:42:44 +00:00
|
|
|
server::wait_for_local_worker(&wid).await.unwrap();
|
|
|
|
}
|
2019-04-11 06:26:52 +00:00
|
|
|
}
|
2019-08-29 08:05:43 +00:00
|
|
|
});
|
2019-04-11 06:26:52 +00:00
|
|
|
|
|
|
|
let data = errmsg.lock().unwrap();
|
|
|
|
match *data {
|
|
|
|
Some(ref err) => bail!("Error: {}", err),
|
|
|
|
None => {},
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|