mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 08:26:04 +00:00
Tests: the empty-params command sweeps leave plug-in caches alone
every_command_survives_empty_params and
read_only_commands_read_the_instance_of_a_picked_object run every command
with {}. That includes plugin.clearCache, which without an id empties the
cache of every plug-in installed in the process. When either sweep ran
during plugin_storage_is_capped_and_survives_a_damaged_settings_file
(called from plugins_keep_settings_and_a_cache_of_their_own_in_the_store),
it deleted that test's cache entries Tile and tile. The test's
st.clear_cache() == MAX_CACHE_BYTES + 3 assertion after the
MAX_CACHE_SCAN folders then failed with 536870912 bytes freed.
Both sweeps now leave plugin.clearCache out.
tests/plugin_clear_cache.rs already runs it with {} in a test binary of
its own. A new test runs the other plug-in commands with {} in the
selection states that every_command_survives_empty_params uses, and checks
that an installed plug-in's cache keeps its 3 bytes.
This commit is contained in:
@@ -3242,6 +3242,40 @@ fn removing_an_id_that_is_not_installed_deletes_its_storage() {
|
||||
assert!(s.execute("plugin.remove", &json!({"id": id})).is_err(), "nothing left to remove");
|
||||
}
|
||||
|
||||
/// The `plugin.*` commands that the tests running every command with `{}` run
|
||||
/// ([`crate::runs_with_empty_params`]) leave the cache of an installed plug-in as it is, so
|
||||
/// those tests can run beside the ones here that check a cache. Each command runs with `{}` in a
|
||||
/// document with two rectangles, one or both selected, as `every_command_survives_empty_params`
|
||||
/// runs it.
|
||||
#[test]
|
||||
fn plugin_commands_run_with_empty_params_keep_other_plugins_caches() {
|
||||
let folder = crate::tests_links::Folder::new("plugin-storage-empty-params");
|
||||
let id = "test.engine.storageemptyparams";
|
||||
let mut s = session();
|
||||
s.attach_plugin_store(folder.0.clone());
|
||||
install_storing(&mut s, id, WRITES);
|
||||
run(&mut s, "plugin.run", json!({"id": id, "ids": []}));
|
||||
assert_eq!(run(&mut s, "plugin.info", json!({"id": id}))["cacheBytes"], json!(3));
|
||||
let mut ran = vec![];
|
||||
for all in [false, true] {
|
||||
for c in crate::cmd::command_specs().iter().filter(|c| c.id.starts_with("plugin.") && crate::runs_with_empty_params(c.id)) {
|
||||
let mut other = session();
|
||||
let a = rect(&mut other, 10.0, "#ff0000");
|
||||
rect(&mut other, 40.0, "#0000ff");
|
||||
if all {
|
||||
run(&mut other, "select.all", json!({}));
|
||||
} else {
|
||||
run(&mut other, "select.set", json!({"ids": [a.0]}));
|
||||
}
|
||||
let _ = other.execute(c.id, &json!({}));
|
||||
ran.push(c.id);
|
||||
assert_eq!(run(&mut s, "plugin.info", json!({"id": id}))["cacheBytes"], json!(3), "after {}", c.id);
|
||||
}
|
||||
}
|
||||
assert!(ran.contains(&"plugin.list"), "{ran:?}");
|
||||
run(&mut s, "plugin.remove", json!({"id": id}));
|
||||
}
|
||||
|
||||
/// The settings file and the cache are checked: a file that doesn't read is moved aside and the
|
||||
/// settings start empty; a write past a cap fails and changes nothing; cache entries whose names
|
||||
/// differ only in case are two files; a removed plug-in's storage takes no more writes.
|
||||
|
||||
Reference in New Issue
Block a user