]> git.proxmox.com Git - proxmox-backup.git/commitdiff
tools/BroadcastFuture: add testcase for better understanding
authorStefan Reiter <s.reiter@proxmox.com>
Mon, 7 Jun 2021 15:35:24 +0000 (17:35 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 8 Jun 2021 07:42:29 +0000 (09:42 +0200)
Explicitly test that data will stay available and can be retrieved
immediately via listen(), even if the future producing the data and
notifying the consumers was already run in the past.

Wasn't broken or anything, but helps with understanding IMO.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
src/tools/broadcast_future.rs

index 88b7aaab7788f49e44bbb1cac13a6f804dd954b3..7bfd83b7a1831447e68bfa3623306074cc9b9a59 100644 (file)
@@ -166,4 +166,15 @@ fn test_broadcast_future() {
     let result = CHECKSUM.load(Ordering::SeqCst);
 
     assert_eq!(result, 3);
+
+    // the result stays available until the BroadcastFuture is dropped
+    rt.block_on(sender.listen()
+        .map_ok(|res| {
+            CHECKSUM.fetch_add(res*4, Ordering::SeqCst);
+        })
+        .map_err(|err| { panic!("got error {}", err); })
+        .map(|_| ()));
+
+    let result = CHECKSUM.load(Ordering::SeqCst);
+    assert_eq!(result, 7);
 }