Skip to content

Add a fake backend for component tests - #50

Closed
lforchini wants to merge 1 commit into
test/05-config-single-prefixfrom
test/06-fake-backend
Closed

lforchini wants to merge 1 commit into
test/05-config-single-prefixfrom
test/06-fake-backend

Conversation

@lforchini

Copy link
Copy Markdown
Collaborator

The harness needs a VM the daemon can discover and scale without
libvirt. JSON files carry the snapshot, and set_thread_count records
each target so tests can assert behavior.

Signed-off-by: Leonardo Forchini leonardo.forchini@nutanix.com


Stack created with GitHub Stacks CLI • Give Feedback 💬

@lforchini
lforchini added this pull request to stack #55 September 28, 2026 12:50
The harness needs a VM the daemon can discover and scale without
libvirt. JSON files carry the snapshot, and set_thread_count records
each target so tests can assert behavior.

Signed-off-by: Leonardo Forchini <leonardo.forchini@nutanix.com>
Comment thread src/backends/fake/mod.rs
//!
//! Each VM is one JSON file in `state_dir`. The pytest harness updates that
//! file; every snapshot re-reads it. `set_thread_count` writes the new count
//! back and appends the target to `calls.jsonl`. A sibling `.lock` file,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, typo in jsonl?

Comment thread src/backends/fake/mod.rs
fn discover_vms(state_dir: &Path) -> Vec<Arc<Instance>> {
let entries = match fs::read_dir(state_dir) {
Ok(entries) => entries,
Err(error) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we expect in this case?

Comment thread src/backends/fake/mod.rs
let mut instances = Vec::new();
for entry in entries.flatten() {
let path = entry.path();
if path.extension().and_then(|ext| ext.to_str()) != Some("json") {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we expecting anything else other than .json files? I see you have similar logic below, if there's auxiliary files then put them in a directory and ignore that specific directory?

Comment thread src/backends/fake/mod.rs
/// Read one VM file, or log and return `None` when it cannot be parsed.
#[tracing::instrument(skip(path, id), fields(vm = id))]
fn read_vm(path: &std::path::Path, id: &str) -> Option<VmFile> {
let _guard = match LockGuard::acquire(&lock_path_for(path)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we expect in this case?

Comment thread Cargo.toml
default = ["threshold-engine", "qemu-backend", "tui"]
threshold-engine = []
qemu-backend = ["dep:once_cell", "dep:virt"]
# In-process VM stand-in used by component tests. Not part of a production build.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume enabling this for tests land in a later commit?

@lforchini lforchini closed this Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants