The same-instant lesson fixtures the uniqueness wall outlawed
Browse files at this commit89b83c89eaf8c304fd8ec34a3b24f0176760de9aParent: aa7132a- test
- the same-instant lesson fixtures the uniqueness wall outlawed
2 changed files +18 -4
tests/partial_patch_sessions.rsmodified+12 -3
| @@ -25,7 +25,12 @@ async fn concurrent_partial_patches_keep_both_fields() { | |||
| 25 | "POST", | 25 | "POST", |
| 26 | &format!("/instances/{}/sessions", t.instance), | 26 | &format!("/instances/{}/sessions", t.instance), |
| 27 | Some(&who), | 27 | Some(&who), |
| 28 | - Some(json!({ "topic": "old topic", "starts_at": FUTURE })), | 28 | + // `UNIQUE (class_course, starts_at)`: each round takes its own |
| 29 | + // instant — descending, all still future, all before the fixed | ||
| 30 | + // ends patch below. | ||
| 31 | + Some( | ||
| 32 | + json!({ "topic": "old topic", "starts_at": FUTURE - round as i64 * 3_600_000 }), | ||
| 33 | + ), | ||
| 29 | ) | 34 | ) |
| 30 | .await; | 35 | .await; |
| 31 | assert_eq!(created.status, StatusCode::CREATED, "round {round} create"); | 36 | assert_eq!(created.status, StatusCode::CREATED, "round {round} create"); |
| @@ -71,15 +76,19 @@ async fn concurrent_range_patches_never_invert_the_stored_row() { | |||
| 71 | let who = login_as(&app, &db, "range", "teacher").await; | 76 | let who = login_as(&app, &db, "range", "teacher").await; |
| 72 | let mudur = login_as(&app, &db, "mudur", "manager").await; | 77 | let mudur = login_as(&app, &db, "mudur", "manager").await; |
| 73 | let t = taught_under(&app, &mudur, &who, "math").await; | 78 | let t = taught_under(&app, &mudur, &who, "math").await; |
| 74 | - let ends = FUTURE + 3_600_000; | ||
| 75 | 79 | ||
| 76 | for round in 0..20 { | 80 | for round in 0..20 { |
| 81 | + // `UNIQUE (class_course, starts_at)`: each round takes its own | ||
| 82 | + // instant — descending, all still future, ends = starts + 1h kept. | ||
| 83 | + let starts = FUTURE - round as i64 * 3_600_000; | ||
| 84 | + let ends = starts + 3_600_000; | ||
| 85 | + | ||
| 77 | let created = send( | 86 | let created = send( |
| 78 | &app, | 87 | &app, |
| 79 | "POST", | 88 | "POST", |
| 80 | &format!("/instances/{}/sessions", t.instance), | 89 | &format!("/instances/{}/sessions", t.instance), |
| 81 | Some(&who), | 90 | Some(&who), |
| 82 | - Some(json!({ "starts_at": FUTURE, "ends_at": ends })), | 91 | + Some(json!({ "starts_at": starts, "ends_at": ends })), |
| 83 | ) | 92 | ) |
| 84 | .await; | 93 | .await; |
| 85 | assert_eq!(created.status, StatusCode::CREATED, "round {round} create"); | 94 | assert_eq!(created.status, StatusCode::CREATED, "round {round} create"); |
tests/regress_badges.rsmodified+6 -1
| @@ -360,8 +360,13 @@ fn soon() -> i64 { | |||
| 360 | /// `POST /instances/{id}/sessions` and the session PATCH refuse a start time in | 360 | /// `POST /instances/{id}/sessions` and the session PATCH refuse a start time in |
| 361 | /// the past — which is what makes the counter's own gate worth having, since a | 361 | /// the past — which is what makes the counter's own gate worth having, since a |
| 362 | /// client can only ever schedule *forward* into an unheld lesson. | 362 | /// client can only ever schedule *forward* into an unheld lesson. |
| 363 | +/// | ||
| 364 | +/// The shift is *relative* to the row's own start, not a shared constant: | ||
| 365 | +/// `UNIQUE (class_course, starts_at)` makes two lessons of one section unable | ||
| 366 | +/// to share an instant, so pinning every row to `1` would itself be a | ||
| 367 | +/// violation once a test rings more than one bell on one section. | ||
| 363 | async fn ring_the_bell(db: &Database, session: &str) { | 368 | async fn ring_the_bell(db: &Database, session: &str) { |
| 364 | - sqlx::query("UPDATE course_session SET starts_at = 1 WHERE id = $1") | 369 | + sqlx::query("UPDATE course_session SET starts_at = starts_at - 360_000_000 WHERE id = $1") |
| 365 | .bind(hezarfen_backend::domain::course_session::CourseSessionId::from_key(session)) | 370 | .bind(hezarfen_backend::domain::course_session::CourseSessionId::from_key(session)) |
| 366 | .execute(db) | 371 | .execute(db) |
| 367 | .await | 372 | .await |