🌙 two clock-dependent assertions in the suite
Browse files at this commit1675e731a4f8f01ef1c73e77a49e1b7c29c1f685Parent: 4a8829e- fix
- 🌙 two clock-dependent assertions in the suite
2 changed files +24 -18
- tests/integration.rs +11 -2
- tests/rate_limit.rs +13 -16
tests/integration.rsmodified+11 -2
| @@ -28833,7 +28833,11 @@ async fn probe_school_rows_never_reach_the_control_database_on( | |||
| 28833 | .unwrap(); | 28833 | .unwrap(); |
| 28834 | assert_eq!(schools, vec!["beta".to_string(), "demo".to_string()]); | 28834 | assert_eq!(schools, vec!["beta".to_string(), "demo".to_string()]); |
| 28835 | 28835 | ||
| 28836 | - // User search never crosses the wall. | 28836 | + // User search never crosses the wall. Compare the returned names, not the |
| 28837 | + // raw body: a substring match over the serialized JSON also hits the hex of | ||
| 28838 | + // a UUIDv7 id — "ada" rides inside `01a0adad-…`, whose ms-timestamp prefix | ||
| 28839 | + // spells it for a slice of every wall-clock window — so the negative | ||
| 28840 | + // assertion flipped with the clock instead of with the search. | ||
| 28837 | for (cookie, forbidden) in [(&a, "boran"), (&b, "ada")] { | 28841 | for (cookie, forbidden) in [(&a, "boran"), (&b, "ada")] { |
| 28838 | for q in ["b", "a", "boran", "ada", "bstudent"] { | 28842 | for q in ["b", "a", "boran", "ada", "bstudent"] { |
| 28839 | let res = send( | 28843 | let res = send( |
| @@ -28845,8 +28849,13 @@ async fn probe_school_rows_never_reach_the_control_database_on( | |||
| 28845 | ) | 28849 | ) |
| 28846 | .await; | 28850 | .await; |
| 28847 | assert_eq!(res.status, StatusCode::OK, "search {q}: {}", res.body); | 28851 | assert_eq!(res.status, StatusCode::OK, "search {q}: {}", res.body); |
| 28852 | + let named = res.body["items"] | ||
| 28853 | + .as_array() | ||
| 28854 | + .expect("search items") | ||
| 28855 | + .iter() | ||
| 28856 | + .any(|item| item["username"] == forbidden || item["display_name"] == forbidden); | ||
| 28848 | assert!( | 28857 | assert!( |
| 28849 | - !res.body.to_string().contains(forbidden), | 28858 | + !named, |
| 28850 | "GET /users/search?q={q} returned the other school's `{forbidden}`: {}", | 28859 | "GET /users/search?q={q} returned the other school's `{forbidden}`: {}", |
| 28851 | res.body | 28860 | res.body |
| 28852 | ); | 28861 | ); |
tests/rate_limit.rsmodified+13 -16
| @@ -107,14 +107,7 @@ async fn register_and_login_share_the_auth_bucket() { | |||
| 107 | let app = app_with(auth_only(2)).await; | 107 | let app = app_with(auth_only(2)).await; |
| 108 | let creds = json!({ "school": "demo", "username": "ada", "password": "secret1" }); | 108 | let creds = json!({ "school": "demo", "username": "ada", "password": "secret1" }); |
| 109 | 109 | ||
| 110 | - let (status, _, _) = send_as( | 110 | + let (status, _, _) = send_as(&app, "1.1.1.1", "POST", "/auth/register", Some(creds)).await; |
| 111 | - &app, | ||
| 112 | - "1.1.1.1", | ||
| 113 | - "POST", | ||
| 114 | - "/auth/register", | ||
| 115 | - Some(creds), | ||
| 116 | - ) | ||
| 117 | - .await; | ||
| 118 | assert_eq!(status, StatusCode::CREATED); | 111 | assert_eq!(status, StatusCode::CREATED); |
| 119 | let (status, _, _) = send_as( | 112 | let (status, _, _) = send_as( |
| 120 | &app, | 113 | &app, |
| @@ -556,23 +549,27 @@ async fn a_down_database_leaves_each_process_on_its_local_budget() { | |||
| 556 | tokio::time::sleep(Duration::from_secs(RATE_SYNC_TIMEOUT_SECS + 1)).await; | 549 | tokio::time::sleep(Duration::from_secs(RATE_SYNC_TIMEOUT_SECS + 1)).await; |
| 557 | tokio::time::pause(); | 550 | tokio::time::pause(); |
| 558 | 551 | ||
| 559 | - // The table comes back before the read, so the assertion reads the state | 552 | + // The table comes back. A fold parked inside its statement lands the |
| 560 | - // the outage left: no round landed, so there is no row at all — and the | 553 | + // moment it does — real I/O the virtual clock cannot order, which is why |
| 561 | - // unreported deltas are still sitting in the buckets. | 554 | + // this asserts the arithmetic and not the timing: a round that raced the |
| 555 | + // outage never folds the same deltas twice, and the deltas the outage | ||
| 556 | + // could not report are still sitting in the buckets to be carried. | ||
| 562 | tokio::time::resume(); | 557 | tokio::time::resume(); |
| 563 | sqlx::query("ALTER TABLE rate_limit_out RENAME TO rate_limit") | 558 | sqlx::query("ALTER TABLE rate_limit_out RENAME TO rate_limit") |
| 564 | .execute(&db) | 559 | .execute(&db) |
| 565 | .await | 560 | .await |
| 566 | .expect("give the shared table back"); | 561 | .expect("give the shared table back"); |
| 567 | tokio::time::pause(); | 562 | tokio::time::pause(); |
| 568 | - let rows = read_shared_hits(&db).await; | 563 | + let raced: i64 = read_shared_hits(&db).await.iter().sum(); |
| 569 | - assert_eq!(rows, Vec::<i64>::new()); | 564 | + assert!(raced <= 6, "the deltas are folded once: {raced}"); |
| 570 | 565 | ||
| 571 | - // Recovery needs no restart: the next round carries the deltas, and the | 566 | + // Recovery needs no restart. Two rounds, because each limiter's fold is |
| 572 | - // shared row holds everything both processes admitted while it was down. | 567 | + // its own statement: the shared row ends at everything both processes |
| 568 | + // admitted while the table was gone — three each, the local budget. | ||
| 569 | + sync_round().await; | ||
| 573 | sync_round().await; | 570 | sync_round().await; |
| 574 | let rows = read_shared_hits(&db).await; | 571 | let rows = read_shared_hits(&db).await; |
| 575 | - assert_eq!(rows, vec![6]); | 572 | + assert_eq!(rows.iter().sum::<i64>(), 6); |
| 576 | } | 573 | } |
| 577 | 574 | ||
| 578 | /// Boot the app on a real TCP port, `ConnectInfo` wired exactly like `main`. | 575 | /// Boot the app on a real TCP port, `ConnectInfo` wired exactly like `main`. |