Skip to content

Commit

Permalink
Poll mailcrab for startup in functional test
Browse files Browse the repository at this point in the history
  • Loading branch information
marlonbaeten committed Jun 19, 2023
1 parent 0a11b75 commit fe9e01f
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,8 @@ mod test {
Ok(email)
}

async fn test_receive_messages() -> Result<Vec<MailMessageMetadata>, Box<dyn std::error::Error>>
async fn get_messages_metadata() -> Result<Vec<MailMessageMetadata>, Box<dyn std::error::Error>>
{
send_message(true, true, false)?;
sleep(Duration::from_millis(1500)).await;
send_message(true, false, false)?;
sleep(Duration::from_millis(1500)).await;
send_message(false, true, true)?;

let http_port: u16 = parse_env_var("HTTP_PORT", 1080);
let mails: Vec<MailMessageMetadata> =
reqwest::get(format!("http://127.0.0.1:{http_port}/api/messages"))
Expand All @@ -273,18 +267,37 @@ mod test {
Ok(mails)
}


async fn test_receive_messages() -> Result<(), Box<dyn std::error::Error>>
{
send_message(true, true, false)?;
send_message(true, false, false)?;
send_message(false, true, true)?;

Ok(())
}

#[tokio::test]
async fn receive_message() {
let mut cmd = Command::new("cargo")
.arg("run")
.stdout(Stdio::inherit())
.spawn()
.unwrap();

// wait for mailcrab to startup
sleep(Duration::from_millis(20_000)).await;
let messages = test_receive_messages().await;
for _i in 0..60 {
sleep(Duration::from_millis(1_000)).await;

if get_messages_metadata().await.is_ok() {
break;
}
}

test_receive_messages().await.unwrap();
let messages = get_messages_metadata().await.unwrap();

cmd.kill().unwrap();
let messages = messages.unwrap();

assert_eq!(messages.len(), 3);
assert!(messages[0].has_html);
Expand Down

0 comments on commit fe9e01f

Please sign in to comment.