public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Filip Schauer <f.schauer@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox v3 2/2] rest-server: add tests for upid_read_status
Date: Mon, 29 Sep 2025 11:52:32 +0200	[thread overview]
Message-ID: <20250929095236.38251-3-f.schauer@proxmox.com> (raw)
In-Reply-To: <20250929095236.38251-1-f.schauer@proxmox.com>

Test that the task state is correctly extracted from a task log.

Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
---
 proxmox-rest-server/tests/worker_task.rs | 65 ++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100644 proxmox-rest-server/tests/worker_task.rs

diff --git a/proxmox-rest-server/tests/worker_task.rs b/proxmox-rest-server/tests/worker_task.rs
new file mode 100644
index 00000000..c2afc463
--- /dev/null
+++ b/proxmox-rest-server/tests/worker_task.rs
@@ -0,0 +1,65 @@
+use std::fs::{remove_dir_all, write};
+
+use proxmox_rest_server::{
+    init_worker_tasks, upid_log_path, upid_read_status, TaskState, WorkerTask,
+};
+use proxmox_sys::fs::{make_tmp_dir, CreateOptions};
+
+fn upid_read_status_test_helper(log: &str, expected: &TaskState) {
+    let task = WorkerTask::new("x", None, "u@pam".into(), false).unwrap().0;
+    let upid = task.upid();
+    let logfile = upid_log_path(upid).unwrap();
+    write(logfile, log).unwrap();
+
+    let status = upid_read_status(upid).unwrap();
+
+    assert!(&status == expected);
+}
+
+#[tokio::test]
+async fn test_upid_read_status() {
+    let tmpdir = make_tmp_dir("/tmp/", None).unwrap();
+    init_worker_tasks(tmpdir.clone(), CreateOptions::new()).unwrap();
+
+    upid_read_status_test_helper(
+        "2025-09-22T14:31:04+02:00: The quick, brown fox jumps over a lazy dog.\n\
+         2025-09-22T14:31:04+02:00: TASK ERROR: Something went wrong",
+        &TaskState::Error {
+            message: "Something went wrong".into(),
+            endtime: 1758544264,
+        },
+    );
+
+    upid_read_status_test_helper(
+        "1970-01-01T01:00:00+01:00: The quick, brown fox jumps over a lazy dog.\n\
+         1970-01-01T01:00:01+01:00: TASK ERROR: Lorem ipsum dolor sit amet\n\
+         consetetur sadipscing elitr sed diam nonumy eirmod tempor invidunt\n\
+         ut labore et dolore magna aliquyam erat, sed diam voluptua.",
+        &TaskState::Error {
+            message: "Lorem ipsum dolor sit amet".into(),
+            endtime: 1,
+        },
+    );
+
+    upid_read_status_test_helper(
+        "2025-09-24T10:56:12+02:00: Lorem ipsum dolor sit amet\n\
+         2025-09-24T10:56:13+02:00: consetetur sadipscing elitr\n\
+         2025-09-24T10:56:14+02:00: TASK OK",
+        &TaskState::OK {
+            endtime: 1758704174,
+        },
+    );
+
+    upid_read_status_test_helper(
+        "2025-09-23T12:07:49+02:00: Warning 1\n\
+         2025-09-23T12:29:11+02:00: Warning 2\n\
+         2025-09-23T12:29:11+02:00: TASK WARNINGS: 2",
+        &TaskState::Warning {
+            count: 2,
+            endtime: 1758623351,
+        },
+    );
+
+    // Cleanup
+    remove_dir_all(tmpdir).unwrap();
+}
-- 
2.47.3



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


  parent reply	other threads:[~2025-09-29  9:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-29  9:52 [pbs-devel] [PATCH proxmox v3 0/2] fix #5946: rest-server: worker_task: detect task status on multi-line message Filip Schauer
2025-09-29  9:52 ` [pbs-devel] [PATCH proxmox v3 1/2] " Filip Schauer
2025-09-29  9:52 ` Filip Schauer [this message]
2025-10-03 19:08 ` [pbs-devel] applied: [PATCH proxmox v3 0/2] " Thomas Lamprecht

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=20250929095236.38251-3-f.schauer@proxmox.com \
    --to=f.schauer@proxmox.com \
    --cc=pbs-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