feat: harden community production foundation through story 1.5
This commit is contained in:
1 parent
c30461cc92
commit
f6fc2e5c9b
161 files changed
+16758
-2515
No files matched your search
@@ -0,0 +1,115 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn sequence_is_deterministic_and_append_only() {
|
||||
let first = MigrationAuthority::sequence();
|
||||
let second = MigrationAuthority::sequence();
|
||||
assert_eq!(first, second);
|
||||
MigrationAuthority::validate_sequence().unwrap();
|
||||
assert_eq!(
|
||||
first.iter().map(|item| item.version).collect::<Vec<_>>(),
|
||||
vec![1, 2, 3]
|
||||
);
|
||||
assert_eq!(first[0].checksum, "crank-community-baseline-v1");
|
||||
assert_eq!(first[0].source_digest, BASELINE_SOURCE_SHA256);
|
||||
assert_eq!(
|
||||
baseline_source_digest(),
|
||||
BASELINE_SOURCE_SHA256,
|
||||
"baseline v1 source changed; add a new migration instead"
|
||||
);
|
||||
assert_eq!(first[1].checksum.len(), 64);
|
||||
assert!(
|
||||
first[1]
|
||||
.checksum
|
||||
.bytes()
|
||||
.all(|byte| byte.is_ascii_hexdigit() && !byte.is_ascii_uppercase())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_gap_checksum_phase_and_unbounded_backfill_are_rejected() {
|
||||
let base = MigrationAuthority::sequence();
|
||||
for invalid in [
|
||||
{
|
||||
let mut value = base.clone();
|
||||
value[1].version = 3;
|
||||
value
|
||||
},
|
||||
{
|
||||
let mut value = base.clone();
|
||||
value[1].checksum = "0".repeat(64);
|
||||
value
|
||||
},
|
||||
{
|
||||
let mut value = base.clone();
|
||||
value[1].phase = "unknown";
|
||||
value
|
||||
},
|
||||
{
|
||||
let mut value = base.clone();
|
||||
value[1].name = value[0].name;
|
||||
value
|
||||
},
|
||||
{
|
||||
let mut value = base.clone();
|
||||
value[1].transactional = false;
|
||||
value
|
||||
},
|
||||
{
|
||||
let mut value = base.clone();
|
||||
value[1].phase = "migrate";
|
||||
value[1].backfill = BackfillPolicy::Bounded {
|
||||
max_batch_rows: 10_001,
|
||||
max_batch_ms: 60_001,
|
||||
resumable: false,
|
||||
};
|
||||
value
|
||||
},
|
||||
{
|
||||
let mut value = base.clone();
|
||||
value[1].phase = "contract";
|
||||
value[1].compatibility = "window-closed";
|
||||
value[1].contract_evidence = None;
|
||||
value
|
||||
},
|
||||
] {
|
||||
assert_eq!(
|
||||
validate_descriptors(&invalid).unwrap_err().code(),
|
||||
"invalid_contract"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn backfill_batches_are_bounded_and_resumable() {
|
||||
let policy = BackfillPolicy::Bounded {
|
||||
max_batch_rows: 100,
|
||||
max_batch_ms: 1_000,
|
||||
resumable: true,
|
||||
};
|
||||
BackfillBatch {
|
||||
cursor: Some("next-100".to_owned()),
|
||||
max_rows: 100,
|
||||
max_ms: 1_000,
|
||||
}
|
||||
.validate(policy)
|
||||
.unwrap();
|
||||
assert!(
|
||||
BackfillBatch {
|
||||
cursor: None,
|
||||
max_rows: 101,
|
||||
max_ms: 1_000,
|
||||
}
|
||||
.validate(policy)
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn diagnostic_is_bounded_and_does_not_echo_storage_details() {
|
||||
let error = MigrationError::storage("preflight.connect");
|
||||
let rendered = error.to_string();
|
||||
assert!(rendered.len() < 512);
|
||||
assert!(!rendered.contains("postgres://"));
|
||||
assert_eq!(error.code(), "storage_unavailable");
|
||||
}
|
||||
Reference in new issue
Block a user