From: Robert Obkircher <r.obkircher@proxmox.com>
To: Lukas Wagner <l.wagner@proxmox.com>
Cc: pdm-devel@lists.proxmox.com
Subject: Re: [PATCH datacenter-manager 11/20] parallel fetcher: pass arguments to closure in a single type
Date: Fri, 21 Aug 2026 16:00:31 +0200 [thread overview]
Message-ID: <178732083104.243770.17090706260253141150.b4-review@b4> (raw)
In-Reply-To: <20260817125727.454039-12-l.wagner@proxmox.com>
> Unfortunately, some subsystems still require static initialization,
> namely access control and worker tasks. For those we need a setup
> function that is ensure to be only called once in each test binary.
>
> Worker tasks especially require a directory in which it can place task
> logs. For this we create a temporary directory, which we clean up using
> libc::atexit. Unfortunately, tempfile::TempDir does not work for this
> case, since we'd need to put it in a static variable, and `drop` is
> never called for those.
>
> TestApplication is essentially a builder that can be used to produce a
> PdmApplication suitable for tests.
>
> Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
>
> diff --git a/server/tests/common/environment.rs b/server/tests/common/environment.rs
> new file mode 100644
> index 00000000..5dad7b21
> --- /dev/null
> +++ b/server/tests/common/environment.rs
> @@ -0,0 +1,25 @@
> +use proxmox_router::RpcEnvironment;
> +
> +pub struct TestRpcEnvironment;
> +
> +impl RpcEnvironment for TestRpcEnvironment {
> + fn result_attrib_mut(&mut self) -> &mut serde_json::Value {
> + unimplemented!()
> + }
> +
> + fn result_attrib(&self) -> &serde_json::Value {
> + unimplemented!()
> + }
> +
> + fn env_type(&self) -> proxmox_router::RpcEnvironmentType {
> + unimplemented!()
> + }
> +
> + fn set_auth_id(&mut self, _user: Option<String>) {
> + unimplemented!()
> + }
> +
> + fn get_auth_id(&self) -> Option<String> {
> + Some("root@pam".to_string())
> + }
> +}
> diff --git a/server/tests/common/mod.rs b/server/tests/common/mod.rs
> new file mode 100644
> index 00000000..49646706
> --- /dev/null
> +++ b/server/tests/common/mod.rs
> @@ -0,0 +1,56 @@
> +use std::{
> + path::{Path, PathBuf},
> + sync::{Once, OnceLock},
> +};
> +
> +use anyhow::Context;
> +use serde::de::DeserializeOwned;
> +
> +use proxmox_sys::fs::CreateOptions;
> +
> +mod environment;
> +mod test_application;
> +
> +pub use environment::TestRpcEnvironment;
> +pub use test_application::*;
> +
> +pub async fn read_captured_response<T: DeserializeOwned, P: AsRef<Path>>(
> + path: P,
> +) -> Result<T, proxmox_client::Error> {
> + let s = tokio::fs::read_to_string(path.as_ref())
> + .await
> + .with_context(|| format!("could not read from {path}", path = path.as_ref().display()))
> + .unwrap();
> + Ok(serde_json::from_str(&s).unwrap())
> +}
> +
> +static STATIC_TEMP_DIR: OnceLock<PathBuf> = OnceLock::new();
> +
> +extern "C" fn cleanup() {
> + if let Some(dir) = STATIC_TEMP_DIR.get() {
> + let _ = std::fs::remove_dir_all(dir);
> + }
> +}
> +
> +pub fn test_setup() {
> + static INIT: Once = Once::new();
> +
> + INIT.call_once(|| {
> + let file_opts = CreateOptions::new();
> +
> + let dir = proxmox_sys::fs::make_tmp_dir("/tmp", None).unwrap();
A while ago I had a brief discussion with Fabian about how file I/O
should be tested. He argued that tests should not make any assumptions
about the file system outside of CARGO_TARGET_TMPDIR, not even about
/tmp.
But that is only available for real integration tests, not for
unittests.
> + STATIC_TEMP_DIR.set(dir.clone()).unwrap();
> +
> + proxmox_rest_server::init_worker_tasks(dir.clone(), file_opts).unwrap();
> + proxmox_access_control::init::init(&pdm_api_types::AccessControlConfig, dir)
> + .expect("failed to setup access control config");
> +
> + unsafe {
> + libc::atexit(cleanup);
Doesn't this potentially delete files while other threads are stil
accessing them?
--
Robert Obkircher <r.obkircher@proxmox.com>
next prev parent reply other threads:[~2026-08-21 14:00 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 12:57 [PATCH datacenter-manager/proxmox 00/20] inject application context via API macro for easier integration testing Lukas Wagner
2026-08-17 12:57 ` [PATCH proxmox 01/20] router: introduce shared state Lukas Wagner
2026-08-17 13:26 ` Lukas Wagner
2026-08-20 11:23 ` Lukas Wagner
2026-08-21 13:59 ` Robert Obkircher
2026-08-17 12:57 ` [PATCH proxmox 02/20] rest-server: allow to inject " Lukas Wagner
2026-08-17 12:57 ` [PATCH proxmox 03/20] api-macro: support shared state extraction type Lukas Wagner
2026-08-21 13:59 ` Robert Obkircher
2026-08-17 12:57 ` [PATCH datacenter-manager 04/20] context: promote context to a dir-style module Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 05/20] pdm-config: remotes: rename trait methods to read/write/lock Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 06/20] pdm-config: subscriptions: " Lukas Wagner
2026-08-21 14:00 ` Robert Obkircher
2026-08-17 12:57 ` [PATCH datacenter-manager 07/20] remote iterator: pass remote config reader explicitly Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 08/20] context: introduce a ContextFactory to build application context Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 09/20] context: establish PdmApplication object Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 10/20] context: register PdmApplication in router Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 11/20] parallel fetcher: pass arguments to closure in a single type Lukas Wagner
2026-08-21 14:00 ` Robert Obkircher [this message]
2026-08-17 12:57 ` [PATCH datacenter-manager 12/20] parallel fetcher: support a custom client factory Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 13/20] api: sdn: use PdmApplication handle for accessing remotes Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 14/20] tests: add helpers for building API-handler-level integration tests Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 15/20] tests: add example tests for SDN API routes Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 16/20] api-cache: add wrapper type Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 17/20] context: provide api-cache on the app object Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 18/20] api: subscriptions: use PdmApplication instead of globals Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 19/20] pdm-config: subscriptions: drop unused accessor functions Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 20/20] tests: add example tests for remote subscription management Lukas Wagner
2026-08-20 14:54 ` superseded: [PATCH datacenter-manager/proxmox 00/20] inject application context via API macro for easier integration testing Lukas Wagner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=178732083104.243770.17090706260253141150.b4-review@b4 \
--to=r.obkircher@proxmox.com \
--cc=l.wagner@proxmox.com \
--cc=pdm-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox