From 667cc246ffb0a6410ff2d445d3e3ba522c6a2c4e Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 20 Sep 2024 11:30:11 +0100 Subject: feat(remote): add send events status reporting to both tell users where events have been sent / failed to be sent and to provide a status update so the user doesn't think its crashed --- src/bin/git_remote_nostr/push.rs | 3 ++- tests/git_remote_nostr/main.rs | 4 +++- tests/git_remote_nostr/push.rs | 21 +++++++++++++-------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index 05c9197..5bc1cc8 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs @@ -296,14 +296,15 @@ pub async fn run_push( // TODO check whether tip of each branch pushed is on at least one git server // before broadcasting the nostr state if !events.is_empty() { + term.write_line("broadcast to nostr relays:")?; send_events( client, git_repo.get_path()?, events, user_ref.relays.write(), repo_ref.relays.clone(), - false, true, + false, ) .await?; } diff --git a/tests/git_remote_nostr/main.rs b/tests/git_remote_nostr/main.rs index d05f045..5d2dcbb 100644 --- a/tests/git_remote_nostr/main.rs +++ b/tests/git_remote_nostr/main.rs @@ -132,7 +132,9 @@ async fn generate_repo_with_state_event() -> Result<(nostr::Event, GitTestRepo)> let mut p = cli_tester_after_nostr_fetch_and_sent_list_for_push_responds(&git_repo)?; p.send_line("push refs/heads/main:refs/heads/main")?; p.send_line("")?; - p.expect("ok refs/heads/main\r\n")?; + + p.expect_eventually("ok ")?; + p.expect("refs/heads/main\r\n")?; p.expect_eventually("\r\n\r\n")?; p.exit()?; for p in [51, 52, 53, 55, 56, 57] { diff --git a/tests/git_remote_nostr/push.rs b/tests/git_remote_nostr/push.rs index 8a75f37..79e6c01 100644 --- a/tests/git_remote_nostr/push.rs +++ b/tests/git_remote_nostr/push.rs @@ -215,7 +215,8 @@ mod two_branches_in_batch_one_added_one_updated { p.send_line("push refs/heads/main:refs/heads/main")?; p.send_line("push refs/heads/vnext:refs/heads/vnext")?; p.send_line("")?; - p.expect("ok refs/heads/main\r\n")?; + p.expect_eventually("ok ")?; + p.expect("refs/heads/main\r\n")?; p.expect("ok refs/heads/vnext\r\n")?; p.expect_eventually("\r\n\r\n")?; p.exit()?; @@ -626,7 +627,8 @@ mod delete_one_branch { let mut p = cli_tester_after_nostr_fetch_and_sent_list_for_push_responds(&git_repo)?; p.send_line("push :refs/heads/vnext")?; p.send_line("")?; - p.expect("ok refs/heads/vnext\r\n")?; + p.expect_eventually("ok ")?; + p.expect("refs/heads/vnext\r\n")?; p.expect_eventually("\r\n\r\n")?; p.exit()?; for p in [51, 52, 53, 55, 56, 57] { @@ -684,7 +686,8 @@ mod delete_one_branch { cli_tester_after_nostr_fetch_and_sent_list_for_push_responds(&git_repo)?; p.send_line("push :refs/heads/example-branch")?; p.send_line("")?; - p.expect("ok refs/heads/example-branch\r\n")?; + p.expect_eventually("ok ")?; + p.expect("refs/heads/example-branch\r\n")?; p.expect_eventually("\r\n\r\n")?; p.exit()?; for p in [51, 52, 53, 55, 56, 57] { @@ -770,7 +773,8 @@ mod delete_one_branch { cli_tester_after_nostr_fetch_and_sent_list_for_push_responds(&git_repo)?; p.send_line("push :refs/heads/example-branch")?; p.send_line("")?; - p.expect("ok refs/heads/example-branch\r\n")?; + p.expect_eventually("ok ")?; + p.expect("refs/heads/example-branch\r\n")?; p.expect_eventually("\r\n")?; p.exit()?; for p in [51, 52, 53, 55, 56, 57] { @@ -854,7 +858,8 @@ async fn pushes_to_all_git_servers_listed_and_ok_printed() -> Result<()> { let mut p = cli_tester_after_nostr_fetch_and_sent_list_for_push_responds(&git_repo)?; p.send_line("push refs/heads/main:refs/heads/main")?; p.send_line("")?; - p.expect("ok refs/heads/main\r\n")?; + p.expect_eventually("ok ")?; + p.expect("refs/heads/main\r\n")?; p.expect_eventually("\r\n\r\n")?; p.exit()?; for p in [51, 52, 53, 55, 56, 57] { @@ -1075,7 +1080,7 @@ async fn push_2_commits_to_existing_proposal() -> Result<()> { cli_expect_nostr_fetch(&mut p)?; p.expect(format!("fetching {} ref list over filesystem...\r\n", source_path).as_str())?; p.expect("list: connecting...\r\n\r\r\r")?; - p.expect(format!("To {}\r\n", get_nostr_remote_url()?).as_str())?; + p.expect_eventually_and_print(format!("To {}\r\n", get_nostr_remote_url()?).as_str())?; let output = p.expect_end_eventually()?; for p in [51, 52, 53, 55, 56, 57] { @@ -1230,7 +1235,7 @@ async fn force_push_creates_proposal_revision() -> Result<()> { cli_expect_nostr_fetch(&mut p)?; p.expect(format!("fetching {} ref list over filesystem...\r\n", source_path).as_str())?; p.expect("list: connecting...\r\n")?; - p.expect_after_whitespace(format!("To {}\r\n", get_nostr_remote_url()?).as_str())?; + p.expect_eventually_and_print(format!("To {}\r\n", get_nostr_remote_url()?).as_str())?; let output = p.expect_end_eventually()?; for p in [51, 52, 53, 55, 56, 57] { @@ -1380,7 +1385,7 @@ async fn push_new_pr_branch_creates_proposal() -> Result<()> { cli_expect_nostr_fetch(&mut p)?; p.expect(format!("fetching {} ref list over filesystem...\r\n", source_path).as_str())?; p.expect("list: connecting...\r\n\r\r\r")?; - p.expect(format!("To {}\r\n", get_nostr_remote_url()?).as_str())?; + p.expect_eventually_and_print(format!("To {}\r\n", get_nostr_remote_url()?).as_str())?; let output = p.expect_end_eventually()?; for p in [51, 52, 53, 55, 56, 57] { -- cgit v1.2.3