[pbs-devel] [PATCH proxmox-backup 1/9] tools/BroadcastFuture: add testcase for better understanding

Stefan Reiter s.reiter at proxmox.com
Wed Jun 2 16:38:25 CEST 2021


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.

Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
---

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

 src/tools/broadcast_future.rs | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/tools/broadcast_future.rs b/src/tools/broadcast_future.rs
index 88b7aaab..7bfd83b7 100644
--- a/src/tools/broadcast_future.rs
+++ b/src/tools/broadcast_future.rs
@@ -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);
 }
-- 
2.30.2






More information about the pbs-devel mailing list