tools/BroadcastFuture: add testcase for better understanding
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>
This commit is contained in:
parent
f960fc3b6f
commit
400885e620
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user