Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix unstable the channel tests. #267

Merged
merged 1 commit into from
Sep 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions src/process/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,48 +230,53 @@ fn new_pipe() -> Result<(Sender, Receiver)> {
}

#[cfg(test)]
// Tests become unstable if not serial. The cause is not known.
mod tests {
use super::*;
use anyhow::Context;
use nix::sys::wait;
use nix::unistd;
use serial_test::serial;

#[test]
#[serial]
fn test_channel_intermadiate_ready() -> Result<()> {
let (sender, receiver) = &mut intermediate_to_main()?;
match unsafe { unistd::fork()? } {
unistd::ForkResult::Parent { child } => {
wait::waitpid(child, None)?;
let pid = receiver
.wait_for_intermediate_ready()
.with_context(|| "Failed to wait for intermadiate ready")?;
receiver.close()?;
assert_eq!(pid, child);
wait::waitpid(child, None)?;
}
unistd::ForkResult::Child => {
let pid = unistd::getpid();
sender
.intermediate_ready(pid)
.with_context(|| "Failed to send intermadiate ready")?;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this because it would have overwritten the error message in the function that the test is running.

sender.intermediate_ready(pid)?;
sender.close()?;
std::process::exit(0);
}
};

Ok(())
}

#[test]
#[serial]
fn test_channel_id_mapping_request() -> Result<()> {
let (sender, receiver) = &mut intermediate_to_main()?;
match unsafe { unistd::fork()? } {
unistd::ForkResult::Parent { child } => {
receiver
.wait_for_mapping_request()
.with_context(|| "Failed to wait for mapping ack")?;
wait::waitpid(child, None)?;
receiver.wait_for_mapping_request()?;
receiver.close()?;
}
unistd::ForkResult::Child => {
sender
.identifier_mapping_request()
.with_context(|| "Failed to send mapping written")?;
sender.close()?;
std::process::exit(0);
}
};
Expand All @@ -280,14 +285,13 @@ mod tests {
}

#[test]
#[serial]
fn test_channel_id_mapping_ack() -> Result<()> {
let (sender, receiver) = &mut main_to_intermediate()?;
match unsafe { unistd::fork()? } {
unistd::ForkResult::Parent { child } => {
receiver
.wait_for_mapping_ack()
.with_context(|| "Failed to wait for mapping ack")?;
wait::waitpid(child, None)?;
receiver.wait_for_mapping_ack()?;
}
unistd::ForkResult::Child => {
sender
Expand All @@ -301,26 +305,29 @@ mod tests {
}

#[test]
#[serial]
fn test_channel_init_ready() -> Result<()> {
let (sender, receiver) = &mut init_to_intermediate()?;
match unsafe { unistd::fork()? } {
unistd::ForkResult::Parent { child } => {
receiver
.wait_for_init_ready()
.with_context(|| "Failed to wait for init ready")?;
wait::waitpid(child, None)?;
receiver.wait_for_init_ready()?;
receiver.close()?;
}
unistd::ForkResult::Child => {
sender
.init_ready()
.with_context(|| "Failed to send init ready")?;
sender.close()?;
std::process::exit(0);
}
};

Ok(())
}

#[test]
#[serial]
fn test_channel_intermedaite_graceful_exit() -> Result<()> {
let (sender, receiver) = &mut intermediate_to_main()?;
match unsafe { unistd::fork()? } {
Expand All @@ -343,6 +350,7 @@ mod tests {
}

#[test]
#[serial]
fn test_channel_init_graceful_exit() -> Result<()> {
let (sender, receiver) = &mut init_to_intermediate()?;
match unsafe { unistd::fork()? } {
Expand Down