From 1675e731a4f8f01ef1c73e77a49e1b7c29c1f685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 17 Sep 2026 07:53:35 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=8C=99=20two=20clock-dependent=20a?= =?UTF-8?q?ssertions=20in=20the=20suite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - the rate-limit outage test asserted a single-shot read of a row a parked fold may write the instant the table returns; it now asserts the arithmetic (never folded twice, nothing lost) after two round barriers. This is the failure that reddened CI run 35170750886. - the cross-tenant search probe matched a username as a substring of the raw JSON, which also hits the hex of a UUIDv7 id: "ada" rides inside 01a0adad-…, so a correctly scoped response failed for a slice of every ~17.5-minute wall-clock window and passed outside it. It compares the parsed username/display_name now. --- tests/integration.rs | 13 +++++++++++-- tests/rate_limit.rs | 29 +++++++++++++---------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/tests/integration.rs b/tests/integration.rs index 968f6bf..5a37812 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -28833,7 +28833,11 @@ async fn probe_school_rows_never_reach_the_control_database_on( .unwrap(); assert_eq!(schools, vec!["beta".to_string(), "demo".to_string()]); - // User search never crosses the wall. + // User search never crosses the wall. Compare the returned names, not the + // raw body: a substring match over the serialized JSON also hits the hex of + // a UUIDv7 id — "ada" rides inside `01a0adad-…`, whose ms-timestamp prefix + // spells it for a slice of every wall-clock window — so the negative + // assertion flipped with the clock instead of with the search. for (cookie, forbidden) in [(&a, "boran"), (&b, "ada")] { for q in ["b", "a", "boran", "ada", "bstudent"] { let res = send( @@ -28845,8 +28849,13 @@ async fn probe_school_rows_never_reach_the_control_database_on( ) .await; assert_eq!(res.status, StatusCode::OK, "search {q}: {}", res.body); + let named = res.body["items"] + .as_array() + .expect("search items") + .iter() + .any(|item| item["username"] == forbidden || item["display_name"] == forbidden); assert!( - !res.body.to_string().contains(forbidden), + !named, "GET /users/search?q={q} returned the other school's `{forbidden}`: {}", res.body ); diff --git a/tests/rate_limit.rs b/tests/rate_limit.rs index caf2e8b..54c684a 100644 --- a/tests/rate_limit.rs +++ b/tests/rate_limit.rs @@ -107,14 +107,7 @@ async fn register_and_login_share_the_auth_bucket() { let app = app_with(auth_only(2)).await; let creds = json!({ "school": "demo", "username": "ada", "password": "secret1" }); - let (status, _, _) = send_as( - &app, - "1.1.1.1", - "POST", - "/auth/register", - Some(creds), - ) - .await; + let (status, _, _) = send_as(&app, "1.1.1.1", "POST", "/auth/register", Some(creds)).await; assert_eq!(status, StatusCode::CREATED); let (status, _, _) = send_as( &app, @@ -556,23 +549,27 @@ async fn a_down_database_leaves_each_process_on_its_local_budget() { tokio::time::sleep(Duration::from_secs(RATE_SYNC_TIMEOUT_SECS + 1)).await; tokio::time::pause(); - // The table comes back before the read, so the assertion reads the state - // the outage left: no round landed, so there is no row at all — and the - // unreported deltas are still sitting in the buckets. + // The table comes back. A fold parked inside its statement lands the + // moment it does — real I/O the virtual clock cannot order, which is why + // this asserts the arithmetic and not the timing: a round that raced the + // outage never folds the same deltas twice, and the deltas the outage + // could not report are still sitting in the buckets to be carried. tokio::time::resume(); sqlx::query("ALTER TABLE rate_limit_out RENAME TO rate_limit") .execute(&db) .await .expect("give the shared table back"); tokio::time::pause(); - let rows = read_shared_hits(&db).await; - assert_eq!(rows, Vec::::new()); + let raced: i64 = read_shared_hits(&db).await.iter().sum(); + assert!(raced <= 6, "the deltas are folded once: {raced}"); - // Recovery needs no restart: the next round carries the deltas, and the - // shared row holds everything both processes admitted while it was down. + // Recovery needs no restart. Two rounds, because each limiter's fold is + // its own statement: the shared row ends at everything both processes + // admitted while the table was gone — three each, the local budget. + sync_round().await; sync_round().await; let rows = read_shared_hits(&db).await; - assert_eq!(rows, vec![6]); + assert_eq!(rows.iter().sum::(), 6); } /// Boot the app on a real TCP port, `ConnectInfo` wired exactly like `main`.