From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 4D3F31FF0AA for ; Fri, 21 Aug 2026 16:00:42 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 1D35D215A8; Fri, 21 Aug 2026 16:00:42 +0200 (CEST) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: Re: [PATCH datacenter-manager 11/20] parallel fetcher: pass arguments to closure in a single type From: Robert Obkircher To: Lukas Wagner In-Reply-To: <20260817125727.454039-12-l.wagner@proxmox.com> References: <20260817125727.454039-1-l.wagner@proxmox.com> <20260817125727.454039-12-l.wagner@proxmox.com> Date: Fri, 21 Aug 2026 16:00:31 +0200 Message-Id: <178732083104.243770.17090706260253141150.b4-review@b4> X-Mailer: b4 0.16-dev X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1787320806709 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.653 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: TSMWKRBMB3PB24L2QQWSK5XR2H4R6GEM X-Message-ID-Hash: TSMWKRBMB3PB24L2QQWSK5XR2H4R6GEM X-MailFrom: r.obkircher@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: pdm-devel@lists.proxmox.com X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: > 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 > > 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) { > + unimplemented!() > + } > + > + fn get_auth_id(&self) -> Option { > + 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>( > + path: P, > +) -> Result { > + 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 = 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