MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / test_utilization_hold

Function test_utilization_hold

src/environmentd/tests/sql.rs:1451–1579  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1449#[ignore] // TODO: Reenable when https://linear.app/materializeinc/issue/SQL-407 is fixed
1450#[allow(clippy::disallowed_methods)]
1451async fn test_utilization_hold() {
1452 const THIRTY_DAYS_MS: u64 = 30 * 24 * 60 * 60 * 1000;
1453 // `mz_catalog_server` tests indexes, `quickstart` tests tables.
1454 // The bool determines whether we are testing indexes.
1455 const CLUSTERS_TO_TRY: &[&str] = &["mz_catalog_server", "quickstart"];
1456 const QUERIES_TO_TRY: &[&str] = &["SELECT * FROM mz_internal.mz_cluster_replica_statuses"];
1457
1458 let now_millis = 619388520000;
1459 let past_millis = now_millis - THIRTY_DAYS_MS;
1460 let past_since = Timestamp::from(past_millis);
1461
1462 let now = Arc::new(Mutex::new(past_millis));
1463 let now_fn = {
1464 let timestamp = Arc::clone(&now);
1465 NowFn::from(move || *timestamp.lock().unwrap())
1466 };
1467 let data_dir = tempfile::tempdir().unwrap();
1468
1469 // Create the server with the past time, to make sure the table is created.
1470 let server = test_util::TestHarness::default()
1471 .with_now(now_fn)
1472 .data_directory(data_dir.path())
1473 .start()
1474 .await;
1475
1476 // Fast-forward time to make sure the table is still readable at the old time.
1477 *now.lock().unwrap() = now_millis;
1478
1479 let client = server.connect().await.unwrap();
1480
1481 for q in QUERIES_TO_TRY {
1482 let explain_q = &format!("EXPLAIN TIMESTAMP AS JSON FOR {q}");
1483 for cluster in CLUSTERS_TO_TRY {
1484 client
1485 .execute(&format!("SET cluster={cluster}"), &[])
1486 .await
1487 .unwrap();
1488
1489 let row = client.query_one(explain_q, &[]).await.unwrap();
1490 let explain: String = row.get(0);
1491 let explain: TimestampExplanation = serde_json::from_str(&explain).unwrap();
1492
1493 // Assert that we actually used the indexes/tables, as required
1494 for s in &explain.sources {
1495 assert!(s.name.ends_with("compute)"));
1496 }
1497
1498 // If we're not in EpochMilliseconds, the timestamp math below is invalid, so assert that here.
1499 assert!(matches!(
1500 explain.determination.timestamp_context,
1501 TimestampContext::TimelineTimestamp {
1502 timeline: Timeline::EpochMilliseconds,
1503 ..
1504 }
1505 ));
1506 let since = explain
1507 .determination
1508 .since

Callers

nothing calls this directly

Calls 15

cloneFunction · 0.85
nowFunction · 0.85
unwrapMethod · 0.80
lockMethod · 0.80
data_directoryMethod · 0.80
with_nowMethod · 0.80
expectMethod · 0.80
step_forward_byMethod · 0.80
startMethod · 0.45
pathMethod · 0.45
connectMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected