Skip to content

Replace single-example tests with property checks - #47

Open
lforchini wants to merge 1 commit into
test/01-drop-restated-testsfrom
test/02-property-checks
Open

lforchini wants to merge 1 commit into
test/01-drop-restated-testsfrom
test/02-property-checks

Conversation

@lforchini

Copy link
Copy Markdown
Collaborator

Introduce proptest and convert example tests to the property-testing
framework. General behaviour is enforced and the tests are able to catch
non-hardcoded cases.

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
Introduce proptest and convert example tests to the property-testing
framework. General behaviour is enforced and the tests are able to catch
non-hardcoded cases.

Signed-off-by: Leonardo Forchini <leonardo.forchini@nutanix.com>
@lforchini
lforchini force-pushed the test/02-property-checks branch from 885e7a6 to 24d431f Compare September 28, 2026 12:51

@tmakatos tmakatos left a comment

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've only reviewed half of it. Can we standardise test naming? I find test_foo_XXX very useful especially when grepping to see what tests exists for a function. That requires fixing names of existing tests.

/// Test that vQ round-robin mapping spreads queues across IOThreads
/// as evenly as possible.
proptest! {
#[test]

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.

Keep test description?

prop_assert!(max - min <= 1);
}

#[test]

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.

Test description?

/// as evenly as possible.
proptest! {
#[test]
fn round_robin_partitions_queues(

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.

Could you add some inline comments explaining what's been artificially constructed and what's being tested?

let topo = QemuTopology::new(body);
assert_eq!(topo.iothreads, vec!["iot0"]);
assert_eq!(topo.iothread_tids.get("iot0"), Some(&321));
assert_eq!(topo.device_path, "/machine/peripheral/scsi0");

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.

Do we ever use this?


/// Test that a repeated IOThread id keeps the tid from the last line.
#[test]
fn topology_keeps_the_last_tid_for_a_repeated_id() {

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.

Is that even possible? Shouldn't the backend fail in this case?

}
other => panic!("unexpected err: {other:?}"),
}
fn blockstats_reads_one_device() {

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, shouldn't this be named test_parse_blockstats_XXX? Same or above.

/// other I/O.
#[test]
fn parse_blockstats_sums_across_devices() {
fn blockstats_sums_devices() {

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.

ditto

Comment thread src/engines/threshold.rs
EngineTickContext::default()
}

async fn set_observation(

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, add function description since you're touching this file anyway?

Comment thread src/engines/threshold.rs

#[fixture]
fn engine() -> ThresholdEngine {
fn validation_engine(polls: u32) -> ThresholdEngine {

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.

Why get rid of fixtures? They make the body of the test slightly more focused on the behaviour being tested rather than the setting things up.

Comment thread src/engines/threshold.rs
engine.evaluate(&instance, &context()).await,
ScaleAction::Revert(3)
);
fn nearly_eq(left: f64, right: f64) -> bool {

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.

Document how much is acceptable?

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