Remove all global state from the caching system (#863)
* Remove all global state from the caching system This commit is a continuation of an effort to remove usages of `lazy_static!` and similar global state macros which can otherwise be accomodated with passing objects around. Previously there was a global cache system initialized per-process, but it was initialized in a bit of a roundabout way and wasn't actually reachable from the `wasmtime` crate itself. The changes here remove all global state, refactor many of the internals in the cache system, and makes configuration possible through the `wasmtime` crate. Specifically some changes here are: * Usage of `lazy_static!` and many `static` items in the cache module have all been removed. * Global `cache_config()`, `worker()`, and `init()` functions have all been removed. Instead a `CacheConfig` is a "root object" which internally owns its worker and passing around the `CacheConfig` is required for cache usage. * The `wasmtime::Config` structure has grown options to load and parse cache files at runtime. Currently only loading files is supported, although we can likely eventually support programmatically configuring APIs as well. * Usage of the `spin` crate has been removed and the dependency is removed. * The internal `errors` field of `CacheConfig` is removed, instead changing all relevant methods to return a `Result<()>` instead of storing errors internally. * Tests have all been updated with the new interfaces and APIs. Functionally no real change is intended here. Usage of the `wasmtime` CLI, for example, should still enable the cache by default. * Fix lightbeam compilation
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
use wasmtime_environ::cache_init;
|
||||
|
||||
#[test]
|
||||
fn test_cache_default_config_in_memory() {
|
||||
let errors = cache_init::<&str>(true, None, None);
|
||||
assert!(
|
||||
errors.is_empty(),
|
||||
"This test loads config from the default location, if there's one. Make sure it's correct!"
|
||||
);
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
use wasmtime_environ::cache_init;
|
||||
|
||||
#[test]
|
||||
fn test_cache_disabled() {
|
||||
let errors = cache_init::<&str>(false, None, None);
|
||||
assert!(errors.is_empty(), "Failed to disable cache system");
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
use std::fs;
|
||||
use tempfile;
|
||||
use wasmtime_environ::cache_init;
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_cache_fail_calling_init_twice() {
|
||||
let dir = tempfile::tempdir().expect("Can't create temporary directory");
|
||||
let cache_dir = dir.path().join("cache-dir");
|
||||
let baseline_compression_level = 5;
|
||||
|
||||
let config_path = dir.path().join("cache-config.toml");
|
||||
let config_content = format!(
|
||||
"[cache]\n\
|
||||
enabled = true\n\
|
||||
directory = {}\n\
|
||||
baseline-compression-level = {}\n",
|
||||
toml::to_string_pretty(&format!("{}", cache_dir.display())).unwrap(),
|
||||
baseline_compression_level,
|
||||
);
|
||||
fs::write(&config_path, config_content).expect("Failed to write test config file");
|
||||
|
||||
let errors = cache_init(true, Some(&config_path), None);
|
||||
assert!(errors.is_empty());
|
||||
let _errors = cache_init(true, Some(&config_path), None);
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
use std::fs;
|
||||
use tempfile;
|
||||
use wasmtime_environ::cache_init;
|
||||
|
||||
#[test]
|
||||
fn test_cache_fail_invalid_config() {
|
||||
let dir = tempfile::tempdir().expect("Can't create temporary directory");
|
||||
let baseline_compression_level = -4;
|
||||
|
||||
let config_path = dir.path().join("cache-config.toml");
|
||||
let config_content = format!(
|
||||
"[cache]\n\
|
||||
enabled = true\n\
|
||||
directory = {}\n\
|
||||
baseline-compression-level = {}\n",
|
||||
toml::to_string_pretty(&format!("{}", config_path.display())).unwrap(), // directory is a file -- incorrect!
|
||||
baseline_compression_level,
|
||||
);
|
||||
fs::write(&config_path, config_content).expect("Failed to write test config file");
|
||||
|
||||
let errors = cache_init(true, Some(&config_path), None);
|
||||
assert!(!errors.is_empty());
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
use tempfile;
|
||||
use wasmtime_environ::cache_init;
|
||||
|
||||
#[test]
|
||||
fn test_cache_fail_invalid_path_to_config() {
|
||||
let dir = tempfile::tempdir().expect("Can't create temporary directory");
|
||||
let config_path = dir.path().join("cache-config.toml"); // doesn't exist
|
||||
let errors = cache_init(true, Some(&config_path), None);
|
||||
assert!(!errors.is_empty());
|
||||
}
|
||||
Reference in New Issue
Block a user