feat: recheck failed status
All checks were successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
Rust / build (push) Successful in 1m33s

Should a status check for a transient reason and is re-run, this will
allow that to be detected without the need to restart the git-next
server or force a spurious rebase.

Closes kemitix/git-next#88
This commit is contained in:
Paul Campbell 2024-07-12 08:05:41 +01:00
parent fd762e2bd2
commit 5f36282667
3 changed files with 55 additions and 9 deletions

View file

@ -34,8 +34,12 @@ impl Handler<actor::messages::ReceiveCIStatus> for actor::RepoActor {
git::forge::commit::Status::Fail => { git::forge::commit::Status::Fail => {
tracing::warn!("Checks have failed"); tracing::warn!("Checks have failed");
// TODO: (#95) test: repo with next ahead of main and failing CI should notify user // TODO: (#95) test: repo with next ahead of main and failing CI should notify user
// TODO: (#88) recheck after a longer than normal delay actor::delay_send(
actor::logger(&log, "send: nothing"); // replace with messages to send notification and revalidate later addr,
sleep_duration,
actor::messages::ValidateRepo::new(message_token),
&self.log,
);
} }
} }
} }

View file

@ -6,6 +6,8 @@ pub mod messages;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
use std::time::Duration;
use actix::prelude::*; use actix::prelude::*;
use derive_more::Deref; use derive_more::Deref;
@ -103,6 +105,23 @@ impl Actor for RepoActor {
} }
} }
pub fn delay_send<M>(
addr: Addr<RepoActor>,
delay: Duration,
msg: M,
log: &Option<crate::RepoActorLog>,
) where
M: actix::Message + Send + 'static + std::fmt::Debug,
RepoActor: actix::Handler<M>,
<M as actix::Message>::Result: Send,
{
let log_message = format!("send-after-delay: {:?}", msg);
tracing::debug!(log_message);
logger(log, log_message);
std::thread::sleep(delay);
do_send(addr, msg, log)
}
pub fn do_send<M>(_addr: Addr<RepoActor>, msg: M, log: &Option<crate::RepoActorLog>) pub fn do_send<M>(_addr: Addr<RepoActor>, msg: M, log: &Option<crate::RepoActorLog>)
where where
M: actix::Message + Send + 'static + std::fmt::Debug, M: actix::Message + Send + 'static + std::fmt::Debug,

View file

@ -1,7 +1,7 @@
// //
use super::*; use super::*;
#[actix::test] #[test_log::test(actix::test)]
async fn when_pass_should_advance_main_to_next() -> TestResult { async fn when_pass_should_advance_main_to_next() -> TestResult {
//given //given
let fs = given::a_filesystem(); let fs = given::a_filesystem();
@ -31,7 +31,7 @@ async fn when_pass_should_advance_main_to_next() -> TestResult {
Ok(()) Ok(())
} }
#[actix::test] #[test_log::test(actix::test)]
async fn when_pending_should_recheck_ci_status() -> TestResult { async fn when_pending_should_recheck_ci_status() -> TestResult {
//given //given
let fs = given::a_filesystem(); let fs = given::a_filesystem();
@ -61,7 +61,33 @@ async fn when_pending_should_recheck_ci_status() -> TestResult {
Ok(()) Ok(())
} }
#[actix::test] #[test_log::test(actix::test)]
async fn when_fail_should_recheck_after_delay() -> TestResult {
//given
let fs = given::a_filesystem();
let (open_repository, repo_details) = given::an_open_repository(&fs);
let next_commit = given::a_named_commit("next");
//when
let (addr, log) = when::start_actor_with_open_repository(
Box::new(open_repository),
repo_details,
given::a_forge(),
);
addr.send(actor::messages::ReceiveCIStatus::new((
next_commit.clone(),
git::forge::commit::Status::Fail,
)))
.await?;
tokio::time::sleep(std::time::Duration::from_millis(2)).await;
System::current().stop();
//then
log.require_message_containing("send-after-delay: ValidateRepo")?;
Ok(())
}
#[test_log::test(actix::test)]
#[ignore] //TODO: (#95) should notify user #[ignore] //TODO: (#95) should notify user
async fn when_fail_should_notify_user() -> TestResult { async fn when_fail_should_notify_user() -> TestResult {
//given //given
@ -83,9 +109,6 @@ async fn when_fail_should_notify_user() -> TestResult {
System::current().stop(); System::current().stop();
//then //then
tracing::debug!(?log, ""); log.require_message_containing("send: NotifyUser")?;
log.read()
.map_err(|e| e.to_string())
.map(|l| assert!(l.iter().any(|message| message.contains("send: NotifyUser"))))?;
Ok(()) Ok(())
} }