public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Lukas Wagner <l.wagner@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH datacenter-manager 4/6] task cache: tests: add 'make_cache' convenience helper
Date: Fri, 29 May 2026 15:39:49 +0200	[thread overview]
Message-ID: <20260529133951.326103-5-l.wagner@proxmox.com> (raw)
In-Reply-To: <20260529133951.326103-1-l.wagner@proxmox.com>

Most test use similar settings for instantiating the task cache, so it
makes sense to break it out into a helper.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 server/src/remote_tasks/task_cache.rs | 71 +++++++++------------------
 1 file changed, 22 insertions(+), 49 deletions(-)

diff --git a/server/src/remote_tasks/task_cache.rs b/server/src/remote_tasks/task_cache.rs
index 7da92e31..e83a351b 100644
--- a/server/src/remote_tasks/task_cache.rs
+++ b/server/src/remote_tasks/task_cache.rs
@@ -1310,8 +1310,7 @@ mod tests {
 
     const DEFAULT_MAX_SIZE: u64 = 10000;
 
-    #[test]
-    fn test_add_tasks() -> Result<(), Error> {
+    fn make_cache() -> Result<(NamedTempDir, TaskCache), Error> {
         let tmp_dir = NamedTempDir::new()?;
         let cache = TaskCache::new(
             tmp_dir.path(),
@@ -1321,8 +1320,15 @@ mod tests {
             0,
             DEFAULT_MAX_SIZE,
         )
-        .unwrap()
-        .write()?;
+        .unwrap();
+
+        Ok((tmp_dir, cache))
+    }
+
+    #[test]
+    fn test_add_tasks() -> Result<(), Error> {
+        let (_tmp_dir, cache) = make_cache().unwrap();
+        let cache = cache.write().unwrap();
 
         cache.new_file(1000, false)?;
         assert_eq!(cache.cache.archive_files(&cache.lock)?.len(), 1);
@@ -1374,17 +1380,8 @@ mod tests {
 
     #[test]
     fn test_active_tasks_are_migrated_to_archive() -> Result<(), Error> {
-        let tmp_dir = NamedTempDir::new()?;
-        let cache = TaskCache::new(
-            tmp_dir.path(),
-            CreateOptions::new(),
-            3,
-            1,
-            0,
-            DEFAULT_MAX_SIZE,
-        )
-        .unwrap()
-        .write()?;
+        let (_tmp_dir, cache) = make_cache().unwrap();
+        let cache = cache.write().unwrap();
 
         cache.new_file(1000, false)?;
         add_tasks(&cache, vec![task(1000, None), task(1001, None)])?;
@@ -1401,17 +1398,9 @@ mod tests {
 
     #[test]
     fn test_init() -> Result<(), Error> {
-        let tmp_dir = NamedTempDir::new()?;
-        let cache = TaskCache::new(
-            tmp_dir.path(),
-            CreateOptions::new(),
-            3,
-            1,
-            100,
-            DEFAULT_MAX_SIZE,
-        )
-        .unwrap()
-        .write()?;
+        let (_tmp_dir, mut cache) = make_cache().unwrap();
+        cache.rotate_after = 100;
+        let cache = cache.write().unwrap();
 
         cache.init(1000)?;
         assert_eq!(cache.cache.archive_files(&cache.lock)?.len(), 3);
@@ -1442,17 +1431,9 @@ mod tests {
 
     #[test]
     fn test_tracking_tasks() -> Result<(), Error> {
-        let tmp_dir = NamedTempDir::new()?;
-        let cache = TaskCache::new(
-            tmp_dir.path(),
-            CreateOptions::new(),
-            3,
-            1,
-            100,
-            DEFAULT_MAX_SIZE,
-        )
-        .unwrap()
-        .write()?;
+        let (_tmp_dir, mut cache) = make_cache().unwrap();
+        cache.rotate_after = 100;
+        let cache = cache.write().unwrap();
 
         cache.init(1000)?;
 
@@ -1483,22 +1464,14 @@ mod tests {
 
     #[test]
     fn journal_is_applied_if_max_size_exceeded() -> Result<(), Error> {
-        let tmp_dir = NamedTempDir::new()?;
-
         // Should be *just* enough to fit a single task, which means that we apply the journal
         // after adding a second one.
         const ENOUGH_FOR_SINGLE_TASK: u64 = 200;
 
-        let cache = TaskCache::new(
-            tmp_dir.path(),
-            CreateOptions::new(),
-            3,
-            1,
-            100,
-            ENOUGH_FOR_SINGLE_TASK,
-        )
-        .unwrap()
-        .write()?;
+        let (_tmp_dir, mut cache) = make_cache().unwrap();
+        cache.rotate_after = 100;
+        cache.journal_max_size = ENOUGH_FOR_SINGLE_TASK;
+        let cache = cache.write().unwrap();
 
         add_tasks(&cache, vec![task(1000, Some(1010))])?;
         assert!(cache.journal_size()? > 0);
-- 
2.47.3





  parent reply	other threads:[~2026-05-29 13:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-29 13:39 [PATCH datacenter-manager 0/6] fix #7639: task cache: consider running tasks when updating the cutoff timestamp Lukas Wagner
2026-05-29 13:39 ` [PATCH datacenter-manager 1/6] pdm-api-types: add NativeUpid::node() convenience getter Lukas Wagner
2026-05-29 13:39 ` [PATCH datacenter-manager 2/6] task cache: tests: allow to provide an explicit end time in 'task' helper Lukas Wagner
2026-05-29 13:39 ` [PATCH datacenter-manager 3/6] task cache: tests: add get_cutoff helper Lukas Wagner
2026-05-29 13:39 ` Lukas Wagner [this message]
2026-05-29 13:39 ` [PATCH datacenter-manager 5/6] fix #7639: task cache: consider running tasks when updating the cutoff timestamp Lukas Wagner
2026-05-29 13:39 ` [PATCH datacenter-manager 6/6] task cache: poll known active tasks every 30 seconds 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=20260529133951.326103-5-l.wagner@proxmox.com \
    --to=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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal