MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / test_concurrent_writes

Function test_concurrent_writes

src/environmentd/tests/sql.rs:2083–2137  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2081#[mz_ore::test]
2082#[allow(clippy::disallowed_methods)]
2083fn test_concurrent_writes() {
2084 let server = test_util::TestHarness::default().start_blocking();
2085
2086 let num_tables = 10;
2087
2088 {
2089 let mut client = server.connect(postgres::NoTls).unwrap();
2090 for i in 0..num_tables {
2091 client
2092 .batch_execute(&format!("CREATE TABLE t_{i} (a INT, b text, c text)"))
2093 .unwrap();
2094 }
2095 }
2096
2097 let num_threads = 3;
2098 let num_loops = 10;
2099
2100 let mut clients = Vec::new();
2101 for _ in 0..num_threads {
2102 clients.push(server.connect(postgres::NoTls).unwrap());
2103 }
2104
2105 let handles: Vec<_> = clients
2106 .into_iter()
2107 .map(|mut client| {
2108 std::thread::spawn(move || {
2109 for j in 0..num_loops {
2110 for i in 0..num_tables {
2111 let string_a = "A";
2112 let string_b = "B";
2113 client
2114 .batch_execute(&format!(
2115 "INSERT INTO t_{i} VALUES ({j}, '{string_a}', '{string_b}')"
2116 ))
2117 .unwrap();
2118 }
2119 }
2120 })
2121 })
2122 .collect();
2123
2124 for handle in handles {
2125 handle.join().unwrap();
2126 }
2127
2128 let mut client = server.connect(postgres::NoTls).unwrap();
2129
2130 for i in 0..num_tables {
2131 let count = client
2132 .query_one(&format!("SELECT count(*) FROM t_{i}"), &[])
2133 .unwrap()
2134 .get::<_, i64>(0);
2135 assert_eq!(num_loops * num_threads, count);
2136 }
2137}
2138
2139#[mz_ore::test]
2140#[allow(clippy::disallowed_methods)]

Callers

nothing calls this directly

Calls 11

spawnFunction · 0.85
start_blockingMethod · 0.80
unwrapMethod · 0.80
batch_executeMethod · 0.80
connectMethod · 0.45
pushMethod · 0.45
collectMethod · 0.45
mapMethod · 0.45
into_iterMethod · 0.45
joinMethod · 0.45
query_oneMethod · 0.45

Tested by

no test coverage detected