MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / test_concurrent_reads

Function test_concurrent_reads

atomic-core/src/change/store.rs:1006–1030  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1004
1005 #[test]
1006 fn test_concurrent_reads() {
1007 use std::sync::Arc;
1008 use std::thread;
1009
1010 let store = Arc::new(MemoryChangeStore::new());
1011 let change = create_test_change("Concurrent", b"shared data");
1012 let hash = change.hash().unwrap();
1013 store.insert(hash, change);
1014
1015 let handles: Vec<_> = (0..4)
1016 .map(|_| {
1017 let store = Arc::clone(&store);
1018 thread::spawn(move || {
1019 for _ in 0..100 {
1020 assert!(store.has_change(&hash));
1021 let _ = store.get_change(&hash).unwrap();
1022 }
1023 })
1024 })
1025 .collect();
1026
1027 for handle in handles {
1028 handle.join().unwrap();
1029 }
1030 }
1031
1032 // ------------------------------------------------------------------------
1033 // Edge Case Tests

Callers

nothing calls this directly

Calls 6

create_test_changeFunction · 0.70
unwrapMethod · 0.45
hashMethod · 0.45
insertMethod · 0.45
collectMethod · 0.45
get_changeMethod · 0.45

Tested by

no test coverage detected