From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pdm-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id B9DE91FF164 for <inbox@lore.proxmox.com>; Fri, 14 Feb 2025 14:07:44 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0C98019DF4; Fri, 14 Feb 2025 14:07:45 +0100 (CET) From: Lukas Wagner <l.wagner@proxmox.com> To: pdm-devel@lists.proxmox.com Date: Fri, 14 Feb 2025 14:06:37 +0100 Message-Id: <20250214130653.283012-13-l.wagner@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250214130653.283012-1-l.wagner@proxmox.com> References: <20250214130653.283012-1-l.wagner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.010 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pdm-devel] [PATCH proxmox-datacenter-manager v2 12/28] metric collection: add test for fetch_overdue X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion <pdm-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pdm-devel>, <mailto:pdm-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pdm-devel/> List-Post: <mailto:pdm-devel@lists.proxmox.com> List-Help: <mailto:pdm-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel>, <mailto:pdm-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox Datacenter Manager development discussion <pdm-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" <pdm-devel-bounces@lists.proxmox.com> This test ensure that the logic for fetching metrics from remotes which are overdue for collection continues to work as expected. Signed-off-by: Lukas Wagner <l.wagner@proxmox.com> --- .../src/metric_collection/collection_task.rs | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/server/src/metric_collection/collection_task.rs b/server/src/metric_collection/collection_task.rs index 2b4130fe..f1027ccd 100644 --- a/server/src/metric_collection/collection_task.rs +++ b/server/src/metric_collection/collection_task.rs @@ -632,4 +632,66 @@ pub(super) mod tests { drop(task); assert_eq!(handle.await.unwrap(), 2); } + + #[tokio::test] + async fn test_fetch_overdue() { + // Arrange + test_init(); + + let (tx, rx) = tokio::sync::mpsc::channel(10); + let handle = tokio::task::spawn(fake_rrd_task(rx)); + + let settings = CollectionSettings { + collection_interval: Some(60), + ..Default::default() + }; + + let config = make_remote_config(); + + let state_file = NamedTempFile::new(get_create_options()).unwrap(); + let mut state = MetricCollectionState::new(state_file.path().into(), get_create_options()); + + let now = proxmox_time::epoch_i64(); + + // This one should be fetched + state.set_status( + "pve-0-pass".into(), + RemoteStatus { + last_collection: Some(now - 35), + ..Default::default() + }, + ); + // This one should *not* be fetched + state.set_status( + "pve-1-pass".into(), + RemoteStatus { + last_collection: Some(now - 25), + ..Default::default() + }, + ); + + let (_control_tx, control_rx) = tokio::sync::mpsc::channel(10); + + let mut task = MetricCollectionTask { + state, + settings, + metric_data_tx: tx, + control_message_rx: control_rx, + }; + + let next_collection = Instant::now() + Duration::from_secs(30); + + // Act + task.fetch_overdue(&config, next_collection).await; + + // Assert + let status = task.state.get_status("pve-0-pass").unwrap(); + assert!(status.last_collection.unwrap() - now >= 0); + + let status = task.state.get_status("pve-1-pass").unwrap(); + assert_eq!(status.last_collection.unwrap(), now - 25); + + drop(task); + assert_eq!(handle.await.unwrap(), 1); + } } -- 2.39.5 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel