Skip to content
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
15 changes: 13 additions & 2 deletions .github/workflows/corpus-snapshots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
# change can be committed without a local rerun.
corpus-snapshots:
runs-on: ubuntu-latest
# Planning takes 2-6 min (6 min on one core) plus the release build; each
# query stops at 240 s.
# Planning takes a few minutes plus the release build; planning has no
# time limit.
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
Expand All @@ -30,8 +30,19 @@ jobs:
# Caches the registry and compiled dependencies, keyed per job.
- uses: Swatinem/rust-cache@v2

# For tracing a strict failure that main did not cause to the runner's
# hardware or toolchain.
- name: Show runner CPU and toolchain
run: |
lscpu | grep 'Model name' || true
rustc --version

# Strict: a plan that changes at the committed plan's cost fails too
# (#1541), so the PR that moves a tie updates the snapshot.
- name: Check planner snapshots
run: cargo test --release --locked -p asap-planner-cli --test corpus_snapshots -- --include-ignored
env:
STRICT_SNAPSHOTS: 1

- name: Upload regenerated snapshots
if: failure()
Expand Down
57 changes: 47 additions & 10 deletions crates/planner-cli/tests/corpus_snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
//! The planner has no reference answer, so these tests pin its output
//! instead: each corpus query's selected plan (default search) is compared
//! with the committed one, and any change fails until the snapshot is
//! regenerated and the change explained in the PR. A changed plan whose
//! cost equals the committed plan's (relative difference at most 1e-9),
//! with the same accuracy, warnings and errors, passes: the selection may return any of several equal-cost plans, and
//! which one can differ between machines.
//! regenerated and the change explained in the PR. That includes a plan
//! that changes at the committed plan's cost (#1541): the nightly workflow
//! sets `STRICT_SNAPSHOTS=1`, and any difference fails. Without it, as on a
//! local run, a changed plan whose cost equals the committed plan's
//! (relative difference at most 1e-9), with the same accuracy, warnings and
//! errors, passes with a note on stderr: the selection may return any of
//! several equal-cost plans, and which one could differ between machines.
//!
//! Each `tests/corpus_snapshots/<corpus>/corpus.json` declares the shared
//! planning inputs and the queries by stable id; `<id>.json` beside it is
Expand All @@ -17,7 +20,7 @@
//! search over every legal tumbling-window width, with no time limit.
//!
//! A snapshot holds only the plan, never the search that found it: Stage
//! 3's plan (its `PhysicalASAPDAG`, retention on its nodes), its cost and
//! 3's plan (its `PhysicalASAPDAG`, with the retention and lifetime of its nodes), its cost and
//! accepted accuracy per query, and the materialized views; for a query
//! that does not plan, the error. The selection MILP's size and timings,
//! the Stage 1 and Stage 2 candidate lists and the memo are left out. Floats are as
Expand Down Expand Up @@ -150,6 +153,19 @@ fn plan_snapshot(document: &Value) -> Map<String, Value> {
/// the selection may return either, depending on the machine.
const EQUAL_COST_RELATIVE_TOLERANCE: f64 = 1e-9;

/// Whether equal-cost plan changes fail: `STRICT_SNAPSHOTS` is set, as the
/// nightly workflow sets it.
fn strict_snapshots() -> bool {
std::env::var_os("STRICT_SNAPSHOTS").is_some()
}

/// Whether a snapshot whose text changed from `expected` to `actual` still
/// passes: never when `strict`; otherwise when both select plans of the
/// same cost ([`equal_cost_plan`]).
fn changed_snapshot_passes(expected: &str, actual: &str, strict: bool) -> bool {
!strict && equal_cost_plan(expected, actual)
}

/// Whether the snapshot texts `expected` and `actual` select plans of the
/// same cost ([`same_selected_cost`]).
fn equal_cost_plan(expected: &str, actual: &str) -> bool {
Expand Down Expand Up @@ -249,6 +265,7 @@ fn corpus_plans_match_snapshots() {
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner());
let update = std::env::var_os("UPDATE_SNAPSHOTS").is_some();
let strict = strict_snapshots();
// Regenerated snapshots of failing queries, with their full
// `asap_planner` documents for the DAG viewer, for CI to upload.
// Each corpus clears only its own directory: the sketch plan test writes
Expand Down Expand Up @@ -305,8 +322,11 @@ fn corpus_plans_match_snapshots() {
continue;
}
let expected = std::fs::read_to_string(&path).unwrap_or_default();
if expected != actual && equal_cost_plan(&expected, &actual) {
eprintln!("{name}/{id}: plan changed at the committed plan's cost; passes");
if expected != actual && changed_snapshot_passes(&expected, &actual, strict) {
eprintln!(
"{name}/{id}: plan changed at the committed plan's cost; \
passes (fails with STRICT_SNAPSHOTS=1)"
);
} else if expected != actual {
let out = regenerated.join(&name);
std::fs::create_dir_all(&out).unwrap();
Expand Down Expand Up @@ -411,9 +431,10 @@ fn first_difference_names_the_line() {
);
}

/// A changed plan with the committed plan's cost passes: the planner may
/// pick any of several equal-cost plans, and which one depends on the
/// machine. A dearer or cheaper plan, or one that no longer plans, fails.
/// Outside strict mode, a changed plan with the committed plan's cost
/// passes: the planner may pick any of several equal-cost plans, and which
/// one could depend on the machine. A dearer or cheaper plan, or one that
/// no longer plans, fails.
#[test]
fn equal_cost_plans_pass() {
let plan = |cost: f64| json!({"selected": {"cost": {"cost_per_second": cost}, "dag": {}}});
Expand Down Expand Up @@ -457,3 +478,19 @@ fn equal_cost_plans_pass() {
&with(json!({"k": 1404}), json!([0.01]), json!(["w"]))
));
}

/// In strict mode (the nightly workflow) any changed snapshot fails, even
/// one selecting a different plan at the committed plan's cost (#1541):
/// committed `k = 1404`, selected `k = 2863` at the same cost.
#[test]
fn equal_cost_plan_changes_fail_when_strict() {
let snapshot = |k: u64| {
serde_json::to_string_pretty(&json!({
"selected": {"cost": {"cost_per_second": 1.0e-6}, "dag": {"k": k}, "accepted": []},
}))
.unwrap()
};
let (committed, regenerated) = (snapshot(1404), snapshot(2863));
assert!(changed_snapshot_passes(&committed, &regenerated, false));
assert!(!changed_snapshot_passes(&committed, &regenerated, true));
}
14 changes: 4 additions & 10 deletions crates/planner-cli/tests/corpus_snapshots/o11y_bench/q02.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"materialized_views": []
},
"node_id": 1,
"plan_id": "3b3f67a1f3c9d5b2763c9de99557f43e",
"plan_id": "8019fe7bae92df6ec83c708f4523e66d",
"refresh": "at_ingestion",
"retention_ms": 3900000,
"view_state_key": {
Expand Down Expand Up @@ -854,9 +854,7 @@
},
{
"id": 3,
"lifetime": {
"OneEvaluation": "Memory"
},
"lifetime": "None",
"output_schema": {
"closed": true,
"fields": [
Expand Down Expand Up @@ -986,9 +984,7 @@
},
{
"id": 5,
"lifetime": {
"OneEvaluation": "Memory"
},
"lifetime": "None",
"output_schema": {
"closed": true,
"fields": [
Expand Down Expand Up @@ -1044,9 +1040,7 @@
},
{
"id": 6,
"lifetime": {
"OneEvaluation": "Memory"
},
"lifetime": "None",
"output_schema": {
"closed": false,
"fields": [
Expand Down
28 changes: 8 additions & 20 deletions crates/planner-cli/tests/corpus_snapshots/o11y_bench/q05.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"materialized_views": []
},
"node_id": 1,
"plan_id": "782b58d5b5663e0807064a09f1d9b98e",
"plan_id": "c37a9b99850aebeabafb27f2277564b6",
"refresh": "at_ingestion",
"retention_ms": 3900000,
"view_state_key": {
Expand Down Expand Up @@ -80,7 +80,7 @@
"materialized_views": []
},
"node_id": 7,
"plan_id": "782b58d5b5663e0807064a09f1d9b98e",
"plan_id": "c37a9b99850aebeabafb27f2277564b6",
"refresh": "at_ingestion",
"retention_ms": 3900000,
"view_state_key": {
Expand Down Expand Up @@ -1358,9 +1358,7 @@
},
{
"id": 3,
"lifetime": {
"OneEvaluation": "Memory"
},
"lifetime": "None",
"output_schema": {
"closed": true,
"fields": [
Expand Down Expand Up @@ -1490,9 +1488,7 @@
},
{
"id": 5,
"lifetime": {
"OneEvaluation": "Memory"
},
"lifetime": "None",
"output_schema": {
"closed": true,
"fields": [
Expand Down Expand Up @@ -1818,9 +1814,7 @@
},
{
"id": 9,
"lifetime": {
"OneEvaluation": "Memory"
},
"lifetime": "None",
"output_schema": {
"closed": true,
"fields": [
Expand Down Expand Up @@ -1936,9 +1930,7 @@
},
{
"id": 11,
"lifetime": {
"OneEvaluation": "Memory"
},
"lifetime": "None",
"output_schema": {
"closed": true,
"fields": [
Expand Down Expand Up @@ -1981,9 +1973,7 @@
},
{
"id": 12,
"lifetime": {
"OneEvaluation": "Memory"
},
"lifetime": "None",
"output_schema": {
"closed": true,
"fields": [
Expand Down Expand Up @@ -2061,9 +2051,7 @@
},
{
"id": 14,
"lifetime": {
"OneEvaluation": "Memory"
},
"lifetime": "None",
"output_schema": {
"closed": true,
"fields": [
Expand Down
18 changes: 5 additions & 13 deletions crates/planner-cli/tests/corpus_snapshots/o11y_bench/q06.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"materialized_views": []
},
"node_id": 1,
"plan_id": "9b8f7e452816f875449016c748516f92",
"plan_id": "56947e7146d6c733526cc82f09c99686",
"refresh": "at_ingestion",
"retention_ms": 3900000,
"view_state_key": {
Expand Down Expand Up @@ -933,9 +933,7 @@
},
{
"id": 3,
"lifetime": {
"OneEvaluation": "Memory"
},
"lifetime": "None",
"output_schema": {
"closed": true,
"fields": [
Expand Down Expand Up @@ -1065,9 +1063,7 @@
},
{
"id": 5,
"lifetime": {
"OneEvaluation": "Memory"
},
"lifetime": "None",
"output_schema": {
"closed": true,
"fields": [
Expand Down Expand Up @@ -1123,9 +1119,7 @@
},
{
"id": 6,
"lifetime": {
"OneEvaluation": "Memory"
},
"lifetime": "None",
"output_schema": {
"closed": false,
"fields": [
Expand Down Expand Up @@ -1210,9 +1204,7 @@
},
{
"id": 8,
"lifetime": {
"OneEvaluation": "Memory"
},
"lifetime": "None",
"output_schema": {
"closed": false,
"fields": [
Expand Down
8 changes: 2 additions & 6 deletions crates/planner-cli/tests/corpus_snapshots/o11y_bench/q11.json
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,7 @@
},
{
"id": 2,
"lifetime": {
"OneEvaluation": "Memory"
},
"lifetime": "None",
"output_schema": {
"closed": true,
"fields": [
Expand Down Expand Up @@ -489,9 +487,7 @@
},
{
"id": 4,
"lifetime": {
"OneEvaluation": "Memory"
},
"lifetime": "None",
"output_schema": {
"closed": true,
"fields": [
Expand Down
Loading
Loading