forge
Explore
Log in

Don't you dare go Hollow

Streams open with a retry field, and the registry sweep test follows the grace period

Browse files at this commit

59f426172dc406a73db0e43e6dfe07a4159b532fAhmet Kaan GümüşParent: 806ecd8
  • test
    • streams open with a retry field, and the registry sweep test follows the grace period
Show full message
✅ test: streams open with a retry field, and the registry sweep test follows the grace period
crates/forge-web/src/live.rsmodified+2 -1
@@ -119,7 +119,8 @@ impl LiveHub {
119 pub fn bump_repo(&self, owner_id: &str, repo_id: &str) {119 pub fn bump_repo(&self, owner_id: &str, repo_id: &str) {
120 self.bump(&Topic::User(owner_id.to_owned()));120 self.bump(&Topic::User(owner_id.to_owned()));
121 self.bump(&Topic::Explore);121 self.bump(&Topic::Explore);
122- self.bump(&Topic::Repo(repo_id.to_owned())); }122+ self.bump(&Topic::Repo(repo_id.to_owned()));
123+ }
123 }124 }
124 125
125 /// The state a stream follows between wakes: the receivers of its topics, the read, and the126 /// The state a stream follows between wakes: the receivers of its topics, the read, and the
crates/forge-web/src/oci/gc.rsmodified+4 -1
@@ -33,7 +33,10 @@ pub async fn lock() -> MutexGuard<'static, ()> {
33 pub async fn sweep(state: &AppState, package_id: &str) -> forge_core::Result<usize> {33 pub async fn sweep(state: &AppState, package_id: &str) -> forge_core::Result<usize> {
34 let _guard = lock().await;34 let _guard = lock().await;
35 let linked_before = forge_core::time::stamp_ago(GRACE);35 let linked_before = forge_core::time::stamp_ago(GRACE);
36- let dropped = state.store.oci_sweep_unreferenced(package_id, &linked_before).await?;36+ let dropped = state
37+ .store
38+ .oci_sweep_unreferenced(package_id, &linked_before)
39+ .await?;
37 for digest in &dropped {40 for digest in &dropped {
38 if state.store.oci_digest_linked(digest).await? {41 if state.store.oci_digest_linked(digest).await? {
39 continue;42 continue;
crates/forge-web/src/pages/pull_reviews.rsmodified+11 -19
@@ -397,12 +397,10 @@ async fn review_comment_post(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<Se
397 )397 )
398 .await398 .await
399 {399 {
400- Ok(_) => {400+ Ok(_) => Ok(see_other(format!(
401- Ok(see_other(format!(401+ "{files}#L-{file_index}-{}-{line}",
402- "{files}#L-{file_index}-{}-{line}",402+ side.as_str()
403- side.as_str()403+ ))),
404- )))
405- }
406 Err(forge_core::Error::Invalid(_)) => {404 Err(forge_core::Error::Invalid(_)) => {
407 Ok(see_other(format!("{back}&review_error={ERR_INVALID}")))405 Ok(see_other(format!("{back}&review_error={ERR_INVALID}")))
408 }406 }
@@ -434,9 +432,7 @@ async fn review_comment_reply(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<S
434 .reply_review_comment(&pr.issue.id, &user.id, &root, &form.body)432 .reply_review_comment(&pr.issue.id, &user.id, &root, &form.body)
435 .await433 .await
436 {434 {
437- Ok(_) => {435+ Ok(_) => Ok(see_other(format!("{tab}{anchor}"))),
438- Ok(see_other(format!("{tab}{anchor}")))
439- }
440 Err(forge_core::Error::Invalid(_)) => Ok(refusal(&tab, ERR_INVALID, &anchor)),436 Err(forge_core::Error::Invalid(_)) => Ok(refusal(&tab, ERR_INVALID, &anchor)),
441 Err(e) => Err(e.into()),437 Err(e) => Err(e.into()),
442 }438 }
@@ -535,13 +531,11 @@ async fn review_comment_edit_save(cx: &Cx, Form(form): Form<ReviewForm>) -> Resu
535 .edit_review_comment(&comment.id, &form.body)531 .edit_review_comment(&comment.id, &form.body)
536 .await532 .await
537 {533 {
538- Ok(()) => {534+ Ok(()) => Ok(see_other(format!(
539- Ok(see_other(format!(535+ "{}#rc-{}",
540- "{}#rc-{}",536+ tab_url(&ctx, number, &form.ret),
541- tab_url(&ctx, number, &form.ret),537+ root_of(&comment)
542- root_of(&comment)538+ ))),
543- )))
544- }
545 Err(forge_core::Error::Invalid(_)) => Ok(refusal(&edit_url, ERR_INVALID, "")),539 Err(forge_core::Error::Invalid(_)) => Ok(refusal(&edit_url, ERR_INVALID, "")),
546 Err(e) => Err(e.into()),540 Err(e) => Err(e.into()),
547 }541 }
@@ -829,9 +823,7 @@ async fn review_dismiss(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOthe
829 .dismiss_review(&review.id, &user.id, &form.reason)823 .dismiss_review(&review.id, &user.id, &form.reason)
830 .await824 .await
831 {825 {
832- Ok(()) => {826+ Ok(()) => Ok(see_other(format!("{tab}#review-{}", review.id))),
833- Ok(see_other(format!("{tab}#review-{}", review.id)))
834- }
835 Err(forge_core::Error::Invalid(_)) => Ok(refusal(&tab, ERR_INVALID, "")),827 Err(forge_core::Error::Invalid(_)) => Ok(refusal(&tab, ERR_INVALID, "")),
836 Err(e) => Err(e.into()),828 Err(e) => Err(e.into()),
837 }829 }
crates/forge-web/tests/browse_e2e.rsmodified+9 -3
@@ -636,7 +636,13 @@ async fn open_stream(http: &Http, path: &str, cookie: Option<&str>) -> reqwest::
636 if let Some(cookie) = cookie {636 if let Some(cookie) = cookie {
637 req = req.header(COOKIE, cookie);637 req = req.header(COOKIE, cookie);
638 }638 }
639- req.send().await.expect("stream request")639+ let mut res = req.send().await.expect("stream request");
640+ // A stream that opens sends its `retry` field first. It is not an event, so it is read here.
641+ if res.status().is_success() {
642+ let retry = next_chunk(&mut res).await.expect("the retry field");
643+ assert!(retry.contains("retry: 1000"), "{retry}");
644+ }
645+ res
640 }646 }
641 647
642 /// The next chunk of a stream. None when nothing arrives within two seconds.648 /// The next chunk of a stream. None when nothing arrives within two seconds.
@@ -843,7 +849,8 @@ async fn issue_streams_follow_writes() {
843 );849 );
844 let target = input_value(&view.body(), "target_id");850 let target = input_value(&view.body(), "target_id");
845 851
846- let writes: [(&str, &[(&str, &str)], &str); 8] = [852+ type Write<'a> = (&'a str, &'a [(&'a str, &'a str)], &'a str);
853+ let writes: [Write; 8] = [
847 (854 (
848 "/tahinli/pub/issues/1/comment",855 "/tahinli/pub/issues/1/comment",
849 &[856 &[
@@ -921,7 +928,6 @@ async fn issue_streams_follow_writes() {
921 assert_eq!(member.status().as_u16(), 200, "private list for its owner");928 assert_eq!(member.status().as_u16(), 200, "private list for its owner");
922 }929 }
923 930
924-
925 #[tokio::test]931 #[tokio::test]
926 async fn browsing_pages_stream_their_changes() {932 async fn browsing_pages_stream_their_changes() {
927 if !tool_on_path("git") {933 if !tool_on_path("git") {
crates/forge-web/tests/oci_e2e.rsmodified+6 -4
@@ -757,7 +757,7 @@ async fn mount_copies_a_blob_across_repositories() {
757 }757 }
758 758
759 #[tokio::test]759 #[tokio::test]
760-async fn deleting_tags_and_manifests_sweeps_the_blobs_nothing_uses() {760+async fn deleting_tags_and_manifests_keeps_fresh_blobs_for_the_grace_period() {
761 let token = generate_token();761 let token = generate_token();
762 let seeded = token.clone();762 let seeded = token.clone();
763 let env = start(move |store| async move {763 let env = start(move |store| async move {
@@ -808,7 +808,9 @@ async fn deleting_tags_and_manifests_sweeps_the_blobs_nothing_uses() {
808 .status,808 .status,
809 404809 404
810 );810 );
811- assert_eq!(http.get(&blob_url(&layer_b), Some(&auth)).await.status, 404);811+ // The blobs were pushed just now: the sweep keeps a link newer than the grace period, since a
812+ // push can still be on its way to a manifest. The store test covers the sweep after it.
813+ assert_eq!(http.get(&blob_url(&layer_b), Some(&auth)).await.status, 200);
812 assert_eq!(http.get(&blob_url(&layer_a), Some(&auth)).await.status, 200);814 assert_eq!(http.get(&blob_url(&layer_a), Some(&auth)).await.status, 200);
813 assert_eq!(http.get(&blob_url(&config), Some(&auth)).await.status, 200);815 assert_eq!(http.get(&blob_url(&config), Some(&auth)).await.status, 200);
814 816
@@ -823,8 +825,8 @@ async fn deleting_tags_and_manifests_sweeps_the_blobs_nothing_uses() {
823 )825 )
824 .await;826 .await;
825 assert_eq!(res.status, 202);827 assert_eq!(res.status, 202);
826- assert_eq!(http.get(&blob_url(&layer_a), Some(&auth)).await.status, 404);828+ assert_eq!(http.get(&blob_url(&layer_a), Some(&auth)).await.status, 200);
827- assert_eq!(http.get(&blob_url(&config), Some(&auth)).await.status, 404);829+ assert_eq!(http.get(&blob_url(&config), Some(&auth)).await.status, 200);
828 let tags = http.get("/v2/tahinli/app/tags/list", Some(&auth)).await;830 let tags = http.get("/v2/tahinli/app/tags/list", Some(&auth)).await;
829 assert_eq!(tags.json()["tags"], serde_json::json!([]));831 assert_eq!(tags.json()["tags"], serde_json::json!([]));
830 }832 }
crates/forge-web/tests/pulls_e2e.rsmodified+11 -1
@@ -564,7 +564,17 @@ async fn open_stream(http: &Http, path: &str, session: Option<&str>) -> reqwest:
564 if let Some(session) = session {564 if let Some(session) = session {
565 req = req.header(COOKIE, session);565 req = req.header(COOKIE, session);
566 }566 }
567- req.send().await.expect("stream request")567+ let mut res = req.send().await.expect("stream request");
568+ // A stream that opens sends its `retry` field first. It is not an event, so it is read here.
569+ if res.status().is_success() {
570+ let retry = tokio::time::timeout(Duration::from_secs(5), res.chunk())
571+ .await
572+ .expect("the retry field")
573+ .expect("stream chunk")
574+ .expect("stream still open");
575+ assert!(String::from_utf8_lossy(&retry).contains("retry: 1000"));
576+ }
577+ res
568 }578 }
569 579
570 /// Waits for the next event of a stream, which must be `changed`.580 /// Waits for the next event of a stream, which must be `changed`.