From 89b83c89eaf8c304fd8ec34a3b24f0176760de9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 24 Sep 2026 17:16:45 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20test(schema):=20the=20same-insta?= =?UTF-8?q?nt=20lesson=20fixtures=20the=20uniqueness=20wall=20outlawed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit UNIQUE (class_course, starts_at) makes two lessons of one section starting together a coded 409, and three fixtures still created them: - partial_patch_sessions: both concurrency tests POSTed a lesson at one shared instant in a 20-round loop; each round now gets its own instant, the racing PATCH targets and every assertion unchanged. - regress_badges' bell helper forced several lessons of one section to starts_at = 1; the shift is now relative to each row's own start, so they stay distinct. GitHub's suite was red on exactly this class. --- tests/partial_patch_sessions.rs | 15 ++++++++++++--- tests/regress_badges.rs | 7 ++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/partial_patch_sessions.rs b/tests/partial_patch_sessions.rs index c1d11e5..f047e99 100644 --- a/tests/partial_patch_sessions.rs +++ b/tests/partial_patch_sessions.rs @@ -25,7 +25,12 @@ async fn concurrent_partial_patches_keep_both_fields() { "POST", &format!("/instances/{}/sessions", t.instance), Some(&who), - Some(json!({ "topic": "old topic", "starts_at": FUTURE })), + // `UNIQUE (class_course, starts_at)`: each round takes its own + // instant — descending, all still future, all before the fixed + // ends patch below. + Some( + json!({ "topic": "old topic", "starts_at": FUTURE - round as i64 * 3_600_000 }), + ), ) .await; assert_eq!(created.status, StatusCode::CREATED, "round {round} create"); @@ -71,15 +76,19 @@ async fn concurrent_range_patches_never_invert_the_stored_row() { let who = login_as(&app, &db, "range", "teacher").await; let mudur = login_as(&app, &db, "mudur", "manager").await; let t = taught_under(&app, &mudur, &who, "math").await; - let ends = FUTURE + 3_600_000; for round in 0..20 { + // `UNIQUE (class_course, starts_at)`: each round takes its own + // instant — descending, all still future, ends = starts + 1h kept. + let starts = FUTURE - round as i64 * 3_600_000; + let ends = starts + 3_600_000; + let created = send( &app, "POST", &format!("/instances/{}/sessions", t.instance), Some(&who), - Some(json!({ "starts_at": FUTURE, "ends_at": ends })), + Some(json!({ "starts_at": starts, "ends_at": ends })), ) .await; assert_eq!(created.status, StatusCode::CREATED, "round {round} create"); diff --git a/tests/regress_badges.rs b/tests/regress_badges.rs index f5a405d..f071885 100644 --- a/tests/regress_badges.rs +++ b/tests/regress_badges.rs @@ -360,8 +360,13 @@ fn soon() -> i64 { /// `POST /instances/{id}/sessions` and the session PATCH refuse a start time in /// the past — which is what makes the counter's own gate worth having, since a /// client can only ever schedule *forward* into an unheld lesson. +/// +/// The shift is *relative* to the row's own start, not a shared constant: +/// `UNIQUE (class_course, starts_at)` makes two lessons of one section unable +/// to share an instant, so pinning every row to `1` would itself be a +/// violation once a test rings more than one bell on one section. async fn ring_the_bell(db: &Database, session: &str) { - sqlx::query("UPDATE course_session SET starts_at = 1 WHERE id = $1") + sqlx::query("UPDATE course_session SET starts_at = starts_at - 360_000_000 WHERE id = $1") .bind(hezarfen_backend::domain::course_session::CourseSessionId::from_key(session)) .execute(db) .await