More tests.

This commit is contained in:
Samuel Guerra 2023-05-30 18:03:41 -03:00
parent 43196349dc
commit 24e0308c0d
2 changed files with 46 additions and 6 deletions

View File

@ -33,9 +33,3 @@
* Review wait, how do handles work when request is not found yet?
* Test live update of localization file.
# Config
* Review save debounce.
* Test concurrent access to same config.
- Use multiple app threads.

View File

@ -205,3 +205,49 @@ fn test_core_border() {
test_config!(BorderStyle::Dotted);
test_config!(BorderSides::new_all(colors::RED));
}
#[test]
fn concurrent_read_write() {
let file = PathBuf::from("../target/tmp/test.concurrent.json");
{
// setup
let _ = std::fs::remove_file(&file);
let mut app = App::default().run_headless(false);
CONFIG.load(JsonConfig::sync(&file));
CONFIG.get("key", || Txt::from_static("default")).set("custom").unwrap();
app.run_task(async {
task::with_deadline(CONFIG.wait_idle(), 5.secs()).await.unwrap();
});
let status = CONFIG.status().get();
if status.is_err() {
panic!("{status}");
}
}
// tests
let threads: Vec<_> = (0..32)
.map(|_| {
std::thread::spawn(clmv!(file, || {
let mut app = App::default().run_headless(false);
CONFIG.load(JsonConfig::sync(file));
app.run_task(async {
task::with_deadline(CONFIG.wait_idle(), 5.secs()).await.unwrap();
});
let var = CONFIG.get("key", || Txt::from_static("default"));
for _ in 0..8 {
assert_eq!("custom", var.get());
var.set("custom").unwrap();
app.update(false).assert_wait();
}
}))
})
.collect();
for t in threads {
t.join().unwrap();
}
}