Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch FileSystemCache to use checked artifact deserialization #3856

Merged
merged 1 commit into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ blake3 = "1.0"
criterion = "0.3"
tempfile = "3.4.0"
rand = "0.8.3"
wasmer = { path = "../api", version = "=3.3.0", default-features = false, features = ["sys", "cranelift"] }
wasmer-compiler-singlepass = { path = "../compiler-singlepass", version = "=3.3.0" }

[features]
Expand All @@ -28,4 +29,4 @@ filesystem = []
blake3-pure = ["blake3/pure"]

[package.metadata.docs.rs]
features = ["wasmer/sys"]
features = ["wasmer/sys"]
22 changes: 22 additions & 0 deletions lib/cache/src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,25 @@ impl Cache for FileSystemCache {
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_fs_cache() {
let dir = tempfile::tempdir().unwrap();

let mut cache = FileSystemCache::new(dir.path()).unwrap();

let engine = wasmer::Engine::default();

let bytes = include_bytes!("../../wasi/tests/envvar.wasm");

let module = Module::from_binary(&engine, bytes).unwrap();
let key = Hash::generate(bytes);

cache.store(key, &module).unwrap();
let _restored = unsafe { cache.load(&engine, key).unwrap() };
}
}