Lost messages when testing a multiprocess application

Following up on my previous question. I have a main process that starts several worker processes. The workers talk with the main process via their stdin/stdout and with each other using pipes. It all works as I expect.

Now I want to run a specific test for both the main process and the workers. So, I make the command

cargo test foo_test --bin worker -- --nocapture arg1 arg2

Everything starts up as I expect, mostly. I print out the PIDs, and the worker PIDs are different from the ones I get back from std::process::Command. I was originally puzzled, but then I realized that the main process gets the PIDs of the test harness, not the workers themselves. No biggie.

The problem is that, while each worker gets the message sent from the main process, the main process gets a message consisting of an empty string instead of what the worker sent. It appears that the test harness is eating the actual message whether I use --nocapture or not. Is there any way to get those messages?

I do get the test report from each worker on its stdout when the worker exits, which is what I was trying to do in the first place. I can always use pipes for the main/worker messaging, so the problem isn't a showstopper. At this point I'm just curious if this behavior is expected.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.